1-Create Function to call Intent 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" />
You want to detect if the browser is Ios or Android and in this case display an icon? I understand correct?
– Sergio
Sergio, regardless of the operating system (iOS or Android) and browser (Chrome, Opera, etc), I need that once the URL is accessed, automatically create an icon on the desktop.
– Alexandre Bonfá