将静态应用快捷方式添加到现有应用时,我遇到了一些问题。我按照https://developer.android.com/guide/topics/ui/shortcuts.html中的步骤操作并显示快捷方式,但是当我点击它时它不会启动活动,而是显示一条吐司消息说:“未安装应用程序”。
这是清单的相关部分:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mypackage">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".activities.SplashActivity"
android:noHistory="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />
</activity>
<activity
android:name=".activities.MainActivity"
android:label="@string/title_activity_main"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".activities.ListActivity"
android:label="@string/title_activity_list"
android:parentActivityName=".activities.MainActivity"
android:theme="@style/AppTheme.NoActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.mypackage.activities.MainActivity" />
</activity>
<activity
android:name=".activities.NewActivity"
android:label="@string/title_activity_new"
android:parentActivityName=".activities.ListActivity"
android:theme="@style/AppTheme.NoActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.mypackage.activities.ListActivity" />
</activity>
<application/>
</manifest>
这是快捷方式.xml 文件:
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
android:shortcutId="shortcut_new_alarm"
android:enabled="true"
android:icon="@mipmap/ic_launcher"
android:shortcutShortLabel="short label"
android:shortcutLongLabel="long label"
android:shortcutDisabledMessage="message">
<intent
android:action="android.intent.action.VIEW"
android:targetPackage="com.mypackage"
android:targetClass="com.mypackage.activities.NewActivity" />
<!-- If your shortcut is associated with multiple intents, include them
here. The last intent in the list determines what the user sees when
they launch this shortcut. -->
<categories android:name="android.shortcut.conversation" />
</shortcut>
<!-- Specify more shortcuts here. -->
</shortcuts>
我已经仔细检查过,目标活动的完整限定名com.mypackage.activities.NewActivity
没问题。
提前致谢!