views:

26

answers:

1

Hello all,

I am trying to create a desktop shortcut to one of my Activity in Android. I use the code that work in every tuto example i have read:

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

And I added the MAIN action to my activity:

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

The result is that the application does not want to launch!

In the Logcat everything seem fine:

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

And the Home tell me that the application is not Installed.

Please help me, I am totally lost and spend a few hours trying to solve the issue and read all info I can get.

Thank a lot!

+1  A: 

Try this:

  1. get rid of the <intent-filter>
  2. get rid of the ACTION_MAIN and just use new Intent(this, MyActivity.class)
CommonsWare
ERROR/Launcher(12197): Launcher does not have the permission to launch Intent { flg=0x10000000 cmp=my.package.name/.MyActivity bnds=[125,534][235,672] (has extras) }. Make sure to create a MAIN intent-filter for the corresponding activity or use the exported attribute for this activity.10-01 02:51:57.701: ERROR/Launcher(12197): java.lang.SecurityException: Permission Denial: starting Intent { flg=0x10000000 cmp=my.package.name/.MyActivity bnds=[125,534][235,672] (has extras) } from ProcessRecord{485b9b38 12197:com.sec.android.app.twlauncher/10005} (pid=12197, uid=10005) requires null
Profete162
@Profete162: Try adding `android:exported="true"` to your `<activity>` element in the manifest.
CommonsWare
Sem OK when adding the Intent. <action android:name="android.intent.action.MAIN" />
Profete162
Yes, I can confirme, the android.intent.action.MAIN is needed
Profete162