Friday, 17 October 2014

how to install shortcut on home screen in andriod



/**
     * add permission for Android manifest xml
     * **/
  <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
/**
     *call method for onCreate method
     * **/
 addShortcutIcon();

/**
     * Adding shortcut for MainActivity
     * Home screen
     * **/
     private void addShortcutIcon() {
   
            Intent shortcutIntent = new Intent(getApplicationContext(),MainActivity.class);       
            shortcutIntent.setAction(Intent.ACTION_MAIN);
            Intent addIntent = new Intent();
            addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
            addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "your app name");
            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);
        }


No comments:

Post a Comment