I have 2 Activities:
1.MainActicity
2.SecondActivity
I wish to create home screen shortcut to second activity:
Intent shortcutIntent = new Intent(getApplicationContext(), SecondActivity.class);
shortcutIntent.setAction(Intent.ACTION_MAIN);
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME,"HelloWorldShortcut");
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(getApplicationContext(),R.drawable.ic_launcher));
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(addIntent);
When I click the shortcut it does nothing and I get toast from my launcher "Unable access the application". But when I add:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
To my second activity, it works just how I wish it to do, but now I have 2 launcher icons in my application.
What I wish is that I`ll have one launcher application and home screen shortcut to my second activity.