How To Add App Launcher Icon To Homescreen On Android Oreo(8.0)?
I am making an android app on Android 8.0. I have read develop doc of shortcut changed before at Using Static Shortcuts but this doc has not method add launcher icon to home scre
Solution 1:
As mentioned on Android Developers
The com.android.launcher.action.INSTALL_SHORTCUT broadcast no longer has any effect on your app, because it is now a private, implicit broadcast. Instead, you should create an app shortcut by using the requestPinShortcut() method from the ShortcutManager class.
Check out this link Android 8.0 Behavior Changes
Solution 2:
As we all know from android version 8.0 many behaviour changes. Try the following code in oreo to create a shortcut icon automatically at the time of install the application.
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) {
Intent shortcutIntent = new Intent(getApplicationContext(), SplashActivity.class);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
shortcutIntent.setAction(Intent.ACTION_MAIN);
ShortcutInfoCompat shortcut = new ShortcutInfoCompat.Builder(getContext(), "shortcut")
.setShortLabel(getResources().getString(R.string.app_name))
.setIcon(IconCompat.createWithResource(getApplicationContext(), R.mipmap.ic_launcher))
.setIntent(shortcutIntent)
.build();
ShortcutManagerCompat.requestPinShortcut(getApplicationContext(), shortcut, null);
}
Post a Comment for "How To Add App Launcher Icon To Homescreen On Android Oreo(8.0)?"