快捷方式启动的活动

问题描述:

我有创建以下列方式快捷方式的应用程序:快捷方式启动的活动

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): Launcher does not have the permission to launch Intent { act=android.intent.action.VIEW flg=0x10000000 cmp=market.finestraprincipale/.MyAppActivity bnds=[3,217][77,296] (has extras) }. Make sure to create a MAIN intent-filter for the corresponding activity or use the exported attribute for this activity. tag=ShortcutInfo(title=myFile) intent=Intent { act=android.intent.action.VIEW flg=0x10000000 cmp=market.finestraprincipale/.MYWEBVIEW bnds=[3,217][77,296] (has extras) }

08-08 14:15:37.907: ERROR/Launcher(165): java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.VIEW flg=0x10000000 cmp=market.finestraprincipale/.MYWEBVIEW bnds=[3,217][77,296] (has extras) } from ProcessRecord{405875c8 165:com.android.launcher/10026} (pid=165, uid=10026) requires null

如何解决这些错误?有没有办法创建同一个应用程序的两个实例?例如,我在我的应用程序中,我创建了一个快捷方式,我按Home按钮,以便应用程序进入背景,当我点击快捷方式时,我开始MYWEBVIEW活动,但在我的应用程序的新实例中...基本上,我可以同时打开更多网页浏览。

您是否拥有manifest.xml的以下权限?

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

还看到你尝试启动活动已经定义了以下意图过滤器:

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

是的,我没有得到创建快捷方式的错误,当我点击快捷方式时得到它......可能会导致它调用一个不是主要的活动..... 。至少我想.. – Sgotenks

+0

尝试添加''permission.INTERNET''。这可能是快捷方式试图启动浏览器(因为您试图打开一个URL)。您是否按照[建议](http://developer.android.com/resources/tutorials/views/hello-webview.html)中的建议对子类“WebViewClient”类进行了分类? –

+0

是的,我正在做两个....如果我通过我的应用程序从主要活动冲浪到MYWEBVIEW,一切工作正常,它打开正确的HTML页面.....但如果我试图从快捷方式打开它直我得到那个错误......可以通过快捷方式打开一个不是主要活动的活动吗?原因,如果我改变了我的应用程序的主要活动的快捷方式的目标,它的工作原理:(但我需要直接去另一个 – Sgotenks

我认为你必须在你的MYWEBVIEW活动中添加 行动 清单文件。我试试这个,它工作。