![](/img/trans.png)
[英]How set badge number in home screen app icon android programatically?
[英]Android Home Screen App Icon With Unwanted Mini-Icon Badge
在添加了使用我的应用程序的快捷方式图标填充设备主屏幕的代码后,该图标显示为别名图标,我尝试在主页上安装主图标以及某种迷你版图标我图标右下角的徽章。 有谁知道如何防止显示此徽章?
EyeSee 图标是我的应用程序的图标。 请注意,我上面的另一个应用程序的图标有一个与主图标不同的迷你徽章。 我很想知道如何创建这个备用徽章图标,但我会非常感激只是暂时摆脱迷你别名图标。
这是我在为主要活动运行 OnCreate 时创建快捷方式的代码。
private void createOrUpdateShortcut()
{
SharedPreferences appPreferences = PreferenceManager.getDefaultSharedPreferences(this);
boolean isAppInstalled = appPreferences.getBoolean("isAppInstalled", false);
if(!isAppInstalled)
{
Context appContext = getApplicationContext();
Intent homeScreenShortCut= new Intent(appContext, MainActivity.class);
homeScreenShortCut.setAction(Intent.ACTION_MAIN);
homeScreenShortCut.putExtra("duplicate", false);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O)
{
homeScreenShortCut.setPackage(appContext.getPackageName());
homeScreenShortCut.setClass(appContext, MainActivity.class);
homeScreenShortCut.setClassName(appContext.getPackageName(), String.valueOf(MainActivity.class));
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
assert shortcutManager != null;
if (shortcutManager.isRequestPinShortcutSupported())
{
ShortcutInfo pinShortcutInfo =
new ShortcutInfo.Builder(this, "browser-shortcut-")
.setShortLabel(appContext.getResources().getString(R.string.app_name))
.setLongLabel(appContext.getResources().getString(R.string.app_name))
.setIcon(Icon.createWithResource(this,R.drawable.ic_launcher))
.setIntent(homeScreenShortCut)
.build();
shortcutManager.requestPinShortcut(pinShortcutInfo, null);
System.out.println("added_to_homescreen");
} else {
System.out.println("failed_to_add");
}
} else {
if(shortcutReinstall)
{
Intent removeIntent = new Intent();
removeIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, homeScreenShortCut);
String prevAppName = appPreferences.getString("appName", getString(R.string.app_name));
removeIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, prevAppName);
removeIntent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(removeIntent);
}
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, homeScreenShortCut);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
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);
}
//Make preference true
SharedPreferences.Editor editor = appPreferences.edit();
editor.putBoolean("isAppInstalled", true);
editor.putString("phoneLanguage", currentLanguage);
editor.putString("appName", getString(R.string.app_name));
editor.commit();
}
}
有谁知道如何防止显示此徽章?
一般来说,这不是一个选择。 固定快捷方式的标准操作系统提供的呈现包括您所说的徽章,并且没有选择退出该徽章的方法。 据推测,这是为了帮助避免应用程序通过这些快捷方式伪装成其他应用程序。
请注意,我上面的另一个应用程序的图标有一个与主图标不同的迷你徽章
我假设您指的是“Patio Motion ...”。 较大的图标是快捷方式的图标。 右下角较小的图标(“徽章”)是应用程序的图标(即显示在设置和其他地方的图标)。
在您的情况下,您似乎已将快捷方式图标设置为与启动器图标相同,这就是您具有这种重复效果的原因。 为快捷方式使用不同的图标,最好是代表该快捷方式正在执行的操作的图标。
就目前而言,您的快捷方式似乎只是启动您的应用程序,这不是快捷方式的用途。 大多数用户可以在他们的主屏幕上放置一个启动器图标,而无需您的应用发布快捷方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.