Background
Android O has various changes of how shortcuts work:
https://developer.android.com/preview/behavior-changes.html#as
The problem
According to recent changes on Android O, the broadcast intent to create shortcuts is completely ignored :
https://developer.android.com/reference/android/content/Intent.html#ACTION_CREATE_SHORTCUT https://developer.android.com/preview/behavior-changes.html#as
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.
This means this code, for example, won't work anymore, no matter which app you've made or which launcher the user has:
private void addShortcut(@NonNull final Context context) {
Intent intent = new Intent().putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(context, MainActivity.class).setAction(Intent.ACTION_MAIN))
.putExtra(Intent.EXTRA_SHORTCUT_NAME, "HelloWorldShortcut")
.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, ShortcutIconResource.fromContext(context, R.mipmap.ic_launcher))
.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
context.sendBroadcast(intent);
}
Currently, even the Play Store itself fails to create shortcuts to apps (at least in the current version: 80795200 ) . It just doesn't do anything, even to Google's launcher.
The question
While I'm very against this change of API (and wrote about it here, here) and here, I'd like to know what would it take to still make it work.
I know there is an API for this, using requestPinShortcut, but this requires the app to target Android O, which means a lot more changes have to be made to make sure the app works there.
My question is: Suppose your app targets Android API 25, how do you create shortcuts on Android O ? Is it possible by using reflection of the newer API ? If so, how?