启动活动的快捷方式

时间:2011-08-09 12:52:13

标签: android permissions android-intent

我有一个应用程序,可以通过以下方式创建快捷方式:

Intent shortcutIntent = new Intent(this, MYWEBVIEW.class);
String fileHtml = trovaHtml(path);
shortcutIntent.putExtra("appToLaunch", appId);
shortcutIntent.putExtra("fileHtml", fileHtml);
shortcutIntent.setAction(Intent.ACTION_VIEW);

Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, dirAppName);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
    Intent.ShortcutIconResource.fromContext(this, R.drawable.icon));
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
this.sendBroadcast(addIntent);

我知道这段代码已被弃用但让我们忘了它.......

MYWEBVIEW不是我的应用程序的主要活动,是一个打开离线html页面的webview,这个html文件的路径在额外值“fileHtml”内。

当我点击快捷方式时,我收到此错误:

  

08-08 14:15:37.907:ERROR / Launcher(165):启动器没有启动Intent的权限{act = android.intent.action.VIEW flg = 0x10000000 cmp = market.finestraprincipale / .MyAppActivity bnds = [3,217] [77,296](有额外内容)}。确保为相应的活动创建MAIN intent-filter或使用此活动的导出属性。 tag = ShortcutInfo(title = myFile)intent = Intent {act = android.intent.action.VIEW flg = 0x10000000 cmp = market.finestraprincipale / .MYWEBVIEW bnds = [3,217] [77,296](有额外内容)}

     

08-08 14:15:37.907:ERROR / Launcher(165):java.lang.SecurityException:Permission Denial:start Intent {act = android.intent.action.VIEW flg = 0x10000000 cmp = market.finestraprincipale /。来自ProcessRecord {405875c8 165:com.android.launcher / 10026}的MYWEBVIEW bnds = [3,217] [77,296](有额外内容)}(pid = 165,uid = 10026)需要null

如何修复这些错误?有没有办法创建同一个应用程序的两个实例?

例如我在我的应用程序中,我创建了一个快捷方式,我按下主页按钮,然后应用程序转到后台,当我点击快捷方式时,我启动MYWEBVIEW活动,但在我的应用程序的新实例内.... 。基本上我可以同时打开更多的网页浏览量。

2 个答案:

答案 0 :(得分:7)

您在manifest.xml中拥有以下权限吗?

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

另请参阅您尝试启动的活动定义了以下意图过滤器:

<intent-filter>
  <action android:name="android.intent.action.MAIN" />
</intent-filter>

答案 1 :(得分:0)

我认为你必须补充一下       行动     在清单文件中的MYWEBVIEW活动中。我试试这个并且它正常工作。

相关问题