Ошибка «Приложение не установлено» при нажатии ярлыка приложения в Nougat 7.1.1

У меня возникают проблемы при добавлении ярлыка статического приложения в существующее приложение. Я выполнил шаги из 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 в порядке.

Заранее спасибо!


person Alejandro Casanova    schedule 14.12.2016    source источник
comment
NewActivity не является вашей активностью запуска, поэтому вы получаете это сообщение.   -  person Maveňツ    schedule 14.12.2016
comment
Какой смысл создавать ярлык для SplashActivity? Что мне нужно, так это ярлык, чтобы перейти к NewActivity вместо SplashActivity. Если вы проверите ссылку, которую я предоставил с официальной документацией, они используют в качестве targetActivity com.example.myapplication.ComposeActivity, в то время как активность запуска является основной. Это то поведение, которое мне нужно.   -  person Alejandro Casanova    schedule 14.12.2016
comment
Пожалуйста, обновите, если вы получили ответ   -  person Akash kumar    schedule 04.12.2017


Ответы (4)


Если вы установите другой productFlavors в build.gradle, вы должны убедиться, что android:targetPackage равно application id, а android:targetClass должно включать имя пакета.

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'
        ...
    }
}

здесь для вашей внутренней версии targetPackage должен быть com.example.app.internal, targetClass должен быть com.example.app.MainActivity

person weei.zh    schedule 20.03.2017
comment
@Pierre, вам следует добавить разные файлы ярлыков.xml для разных типов сборки. - person weei.zh; 09.06.2017
comment
как сделать динамичным?? в xml? с ${applicationId} я пробовал, но, очевидно, он берет полное имя пакета - person Aditi Parikh; 04.09.2017

Измените свой android:targetPackage="com.mypackage" на идентификатор вашего приложения, присутствующий в вашем приложении/градле. Надеюсь, что это поможет вам.

person Nicks    schedule 27.03.2017
comment
Если вы используете другой тип сборки, например. debug и вы добавили applicationIdSuffix, тогда целевой пакет для использования будет applicationId+applicationIdSuffix. Пример: applicationId "com.mypackage" applicationIdSuffix ".debug" android:targetPackage="com.mypackage.debug - person Roberto; 07.02.2019

Просто добавьте android:exported="true" в тег целевой активности в AndroidManifest.xml, а также включите разрешение INSTALL_SHORTCUT.

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

<activity android:name=".activity.MainActivity"
        android:exported="true" />
person Giddy Naya    schedule 23.07.2018

Вы регистрируете свой NewActivity, в то время как Splash является основным действием запуска.

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

Так что просто нужно удалить noHistoty и добавить android:exported="true"

Вот файл ярлыков.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>
person Maveňツ    schedule 14.12.2016
comment
Я понимаю вашу точку зрения, но зачем мне создавать ярлык для SplashActivity? Мне нужно, чтобы ярлык привел меня к NewActivity вместо SplashActivity. Если вы проверите ссылку на официальную документацию, которую они используют в качестве targetActivity com.example.myapplication.ComposeActivity, в то время как активность запуска является основной. Это то поведение, которое мне нужно. - person Alejandro Casanova; 14.12.2016
comment
После изменений, которые вы предлагаете (удаление noHistoty и добавление android:exported=true) в манифест, проблема остается. Если я перемещаю метаданные с информацией о ярлыках в NewActivity, ярлык вообще не отображается. Это решение не устраняет проблему. - person Alejandro Casanova; 16.12.2016