Sometimes it is good to make a shortcut of your application activity so that we can access that activity directly. Assume that we have 10 activities in our application and all activity redirect one to another in order. And i want to see updates on my 5th activity then its time consuming to open that activity by visiting all previous four. So to make this thing better android provide permissions to create a shortcut of any particular activity like this :
set permission in your manifest file :
<uses-permission
android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
and use this method to create a shortcut :
private void createShortcut() {
//Adding shortcut for MainActivity on your Home screen
Intent shortcutIntent = new Intent(getApplicationContext(),
yourActivityname.class);
shortcutIntent.setAction(Intent.ACTION_MAIN);
Intent addIntent = new Intent();
addIntent
.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "shortcut name here");
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);}
0 Comment(s)