我正在尝试为我的应用程序实现应用程序快捷方式,但我无法让它们工作。我的快捷方式.xml:
<Shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
android:shortcutId="shortcut"
android:enabled="true"
android:icon="@drawable/ic_shortcut"
android:shortcutShortLabel="@string/shortcut_label">
<intent
android:action="android.intent.action.VIEW"
android:targetPackage="com.example"
android:targetClass="com.example.package.Activity"/>
</shortcut>
清单.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example">
<application
android:name=".Application"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:resizeableActivity="false"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".package.Activity"
android:label="@string/app_name"
android:launchMode="singleTask"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="@xml/voice_search_params" />
<meta-data android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />
</activity>
所以,我做了与谷歌示例相同的快捷方式。我可以看到并单击快捷方式,但没有任何反应。我尝试了不同的活动,更改了活动位置、活动操作、参数,例如“exported=true”,但没有任何变化 - 在日志中我只能看到
ActivityNotFoundException:快捷方式无法启动
我的快捷方式日志和谷歌相机快捷方式日志之间的唯一区别是活动路径:
I/ActivityManager: 启动 u0 {act=android.intent.action.VIEW flg=0x1000c000 cmp=com.example/.package.Activity}
对比
I/ActivityManager:启动 u0 {act=android.media.action.STILL_IMAGE_CAMERA flg=0x1000c000 cmp=com.google.android.GoogleCamera/com.android.camera.activity.CameraImageActivity}
Google cam 有完整的活动路径,但包路径不同。
PS:今天尝试了谷歌示例,静态应用快捷方式在示例中也不起作用。动态应用快捷方式运行良好。