【问题标题】:Failed to launch shortcut: Application is not installed on your phone启动快捷方式失败:您的手机上没有安装应用程序
【发布时间】:2011-04-19 15:02:36
【问题描述】:

我正在尝试为我在 Android 中的一个 Activity 创建桌面快捷方式。 我使用在我读过的每个 tuto 示例中都可以使用的代码:

    final Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
    ComponentName name = new ComponentName(getPackageName(), ".MyActivity");
    shortcutIntent.setComponent(name);

    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);


    final Intent intent = new Intent();
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);

    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "blabla");
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon);

    intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    sendBroadcast(intent);
    finish();

我将 MAIN 操作添加到我的活动中:

    <activity android:label="@string/app_name" android:name=".MyActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
        </intent-filter>
    </activity>

结果是应用程序不想启动!

在 Logcat 中一切似乎都很好:

10-01 01:17:51.591: INFO/ActivityManager(2424): Starting activity: Intent { act=android.intent.action.MAIN flg=0x14000000 cmp=my.package.name/.MyActivity bnds=[125,384][235,522] (has extras) }

Home 告诉我应用程序没有安装。

请帮助我,我完全迷失了,花了几个小时试图解决问题并阅读我能获得的所有信息。

非常感谢!

【问题讨论】:

    标签: android android-intent launcher


    【解决方案1】:

    试试这个:

    1. 摆脱&lt;intent-filter&gt;
    2. 去掉ACTION_MAIN,直接使用new Intent(this, MyActivity.class)
    3. 在清单中的元素中添加 android:exported="true"

    【讨论】:

    • ERROR/Launcher(12197): Launcher 没有启动 Intent 的权限 { flg=0x10000000 cmp=my.package.name/.MyActivity bnds=[125,534][235,672] (有附加功能) }。确保为相应的活动创建一个主意图过滤器或为此活动使用导出的属性。 10-01 02:51:57.701:错误/启动器(12197):java.lang.SecurityException:权限被拒绝:启动 Intent { flg=0x10000000 cmp=my.package.name/.MyActivity bnds=[125,534][235,672](有附加功能)}来自 ProcessRecord{485b9b38 12197:com.sec.android.app.twlauncher/10005} (pid=12197, uid=10005) 需要 null
    • @Profete162:尝试将android:exported="true" 添加到清单中的&lt;activity&gt; 元素。
    • 添加 Intent 时 Sem OK。
    • 是的,我可以确认,需要 android.intent.action.MAIN
    • Commonsware的评论应该选回答
    【解决方案2】:

    如果您在 AndroidManifest.xml 中声明了两次活动,则可能会发生这种情况,首先是作为启动器,然后只是声明如下:

    <activity android:name=".MyActivity" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-25
      • 1970-01-01
      • 2012-06-14
      相关资源
      最近更新 更多