down
public void installShortCut(){ SharedPreferences appPreferences = PreferenceManager.getDefaultSharedPreferences(this); Boolean isAppInstalled = appPreferences.getBoolean("isAppInstalled",false); if(isAppInstalled==false){ Intent shortcutIntent = new Intent(getApplicationContext(),MainActivy.class); shortcutIntent.setAction(Intent.ACTION_MAIN); Intent intent = new Intent(); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Nome_aplicativo"); intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.ic_launcher)); intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); getApplicationContext().sendBroadcast(intent); SharedPreferences.Editor editor = appPreferences.edit(); editor.putBoolean("isAppInstalled", true); editor.commit(); } }
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />