Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shortcut to launch an activity

I have an app that create a shortcut in the following way:

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

I know that this code is deprecated but let's forget about it.......

MYWEBVIEW is not the main activity of my app, is a webview that open an offline html page, and the path to this html file is inside the extra value "fileHtml".

When i click on the shortcut i get this error:

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

How can I fix these errors? Is there a way to create two instances of the same app?

For example I'm inside my app, I create a shortcut, I press home button so the application goes to background and when I click on the shortcut I start MYWEBVIEW activity but inside a new instance of my app.....so basically I can have more webviews opened at the same time.

like image 307
Sgotenks Avatar asked Aug 09 '11 12:08

Sgotenks


1 Answers

Do you have the following permission in your manifest.xml?

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

Also see that the activity you are trying to launch has the following intent filter defined:

<intent-filter>
  <action android:name="android.intent.action.MAIN" />
</intent-filter>
like image 187
Eugene S Avatar answered Oct 20 '22 07:10

Eugene S