1-Create function to call attempt of shortcut:
private void criarAtalho() {
Intent shortcutIntent = new Intent(getApplicationContext(),
SplashScreen.class);
shortcutIntent.setAction(Intent.ACTION_MAIN);
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "nomeDaApp");
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(getApplicationContext(),
R.mipmap.ic_launcher));
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
addIntent.putExtra("duplicate", false); //may it's already there so don't duplicate
getApplicationContext().sendBroadcast(addIntent);
}
2-write on OnCreat the call of function:
if(!getSharedPreferences("APP_PREFERENCE", Activity.MODE_PRIVATE).
getBoolean("IS_ICON_CREATED", false)){
criarAtalho();
getSharedPreferences("APP_PREFERENCE", Activity.MODE_PRIVATE).
edit().putBoolean("IS_ICON_CREATED", true).commit();
}
3-set the permissions on manifest:
<uses-permission
android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />