[英]How to add icon of the app on the home android screen (react-native)?
在Android上安裝時,主屏沒有添加快捷方式,原來的app有。 您現在只能在應用程序抽屜中找到它。 如何在主屏幕android上添加應用圖標?
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);
}
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);
}
對於多年后出現此問題的任何人,只需確保在AndroidManifest.xml
中聲明電視活動意圖過濾器 ( LEANBACK_LAUNCHER
)。 這將確保它被識別為電視應用程序:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
並包括將顯示在主屏幕上的主屏幕橫幅圖像 ( android:banner
)。此處詳細說明圖像要求:
<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">
React Native 文檔中對此進行了記錄: https://reactnative.dev/docs/building-for-tv ,但尚不清楚更改的實際目的。 官方Android TV docs幫忙解釋一下: https://developer.android.com/training/tv/start/start#tv-activity
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.