App isn´t installed error when tapping app shortcut in Nougat 7.1.1

若如初见. 提交于 2019-12-04 07:28:30

If you set the different productFlavors in build.gradle, you should make sure android:targetPackage is application id, android:targetClass should include package name.

eg:

<shortcut
    android:shortcutId="shortcut_id_xxx"
    android:enabled="true"
    android:icon="@drawable/shortcut_xxx"
    android:shortcutShortLabel="@string/shortcut_xxx">
    <intent
        android:action="android.intent.action.VIEW"
        android:targetPackage="com.example.app.internal"
        android:targetClass="com.example.app.MainActivity" />
    <categories android:name="android.shortcut.conversation" />
</shortcut>

productFlavors {
    internal {
        applicationId 'com.example.app.internal'
        ...
    }
}

in here for your internal version, targetPackage should be com.example.app.internal, targetClass should be com.example.app.MainActivity

Change your android:targetPackage="com.mypackage" to your application id present in your app/gradle. Hope this will help you.

You'r registering your NewActivity while Splash is the Main Launcher Activity.

 <activity
        android:name="com.mypackage.SplashActivity"
        android:label="@string/app_name"
          android:exported="true"
        android:screenOrientation="portrait" >
        <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>

So just need to remove noHistoty and add android:exported="true"

Here is the shortcuts.xml file:

<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>
Giddy Naya

Just add android:exported="true" to your target activity tag under AndroidManifest.xml and also include INSTALL_SHORTCUT permission

<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
...

<activity android:name=".activity.MainActivity"
        android:exported="true" />
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!