'How to add icon of the app on the home android screen (react-native)?
When installing on Android, it does not add a shortcut on home screen, but the app used to. You can find it in the app drawer only now. How to add icon of the app on the home android screen?
Solution 1:[1]
private void removeShortcut () {
Intent shortcutIntent = new Intent(getApplicationContext(),
MainActivity.class);
shortcutIntent.setAction(Intent.ACTION_MAIN);
Intent addIntent = new Intent();
addIntent
.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "HelloWorldShortcut");
addIntent
.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(addIntent);
}
Solution 2:[2]
private void addShortcut() {
Intent shortcutIntent = new Intent(getApplicationContext(), MainActivity.class);
shortcutIntent.setAction(Intent.ACTION_MAIN);
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "HelloWorldShortcut");
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.ic_launcher);
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(addIntent);
}
Solution 3:[3]
For anyone coming to this question years later, just ensure you declare a TV activity intent filter (LEANBACK_LAUNCHER
) in your AndroidManifest.xml
. This will ensure that it is identified as a TV app:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
And include a home screen banner image (android:banner
) which will be displayed on the home screen. Image requirements detailed here:
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="@style/AppTheme"
android:banner="@drawable/tv_banner">
This is documented in the React Native docs: https://reactnative.dev/docs/building-for-tv, but it isn't very clear what the changes are actually for. The official Android TV docs help explain it: https://developer.android.com/training/tv/start/start#tv-activity
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | saloni jain |
Solution 2 | AidenMontgomery |
Solution 3 | Poc275 |