我试图将应用程序快捷方式实现到我的应用程序,但我无法让它们工作。 我shortcut.xml:ActivityNotFoundException:无法启动快捷方式
<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>
的manifest.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>
这样,我的快捷方式相同谷歌的例子。我可以看到并点击快捷方式,但没有任何反应。我尝试过不同的活动,改变活动地点,活动的行动,则params,如“出口=真”,但没有任何变化 - 在日志中我可以看到只有
ActivityNotFoundException:快捷方式无法启动
谷歌拍照快捷登录我的快捷日志之间的唯一差别,是路径的活动:
I/ActivityManager:START U0 {行动= android.intent.action.VIEW FLG = 0x1000c000 CMP = com。示例/.package.Activity}
VS
I/ActivityManager:START U0 {ACT = android.media.action.STILL_IMAGE_CAMERA FLG = 0x1000c000 CMP = com.google.android.GoogleCamera/com.android.camera.activity.CameraImageActivity }
Google cam具有完整的活动路径,但程序包路径不同。
PS:今天尝试谷歌示例,静态应用程序快捷方式也不适用于示例。动态应用快捷方式运作良好。
已经尝试过。没有帮助。 – Anton
您将得到ActivityNotFoundException的原因是,如果Activity未位于它在清单中指向的包中。在Activity java文件的顶部看到的包名称是什么? –
com.example.package,就像在路径中一样。我试图写完整的活动路径,没有任何变化。 – Anton