【问题标题】:How to prevent toast message when creatin app icon on screen在屏幕上创建应用程序图标时如何防止吐司消息
【发布时间】:2012-09-10 05:54:40
【问题描述】:

我想在手机屏幕上创建应用程序图标,我这样做了,但是当我这样做时应用程序会自动创建 toast 消息,如何在创建应用程序时阻止此 toast 消息屏幕上的图标或删除图标? 谢谢。

这是我如何做的代码

private void addShortcut(){
Intent shortcutIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");

// Shortcut name
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
shortcutIntent.putExtra("duplicate", false);

ComponentName comp = new ComponentName(this.getPackageName(), "."+this.getLocalClassName());
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp));

// Shortcut icon
ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);

sendBroadcast(shortcutIntent);
}


private void delShortcut(){
Intent shortcut = new Intent("com.android.launcher.action.UNINSTALL_SHORTCUT");

// Shortcut adı
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));

String appClass = this.getPackageName() + "." +this.getLocalClassName();
ComponentName comp = new ComponentName(this.getPackageName(), appClass);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp));

sendBroadcast(shortcut);
}


public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
delShortcut();
addShortcut();

添加快捷方式的权限

<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"></uses-permission>
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />

【问题讨论】:

    标签: android toast


    【解决方案1】:

    我认为你不能,因为 toast 是由启动器显示的,它与你的应用程序不同。

    我可能是错的。

    无论如何,创建 toast 的不是您的应用,因此您不太可能隐藏它。

    【讨论】:

    • 我不记得 whatsapp 放置了自己的快捷方式。在哪些情况下会创建快捷方式?另外,您检查了哪些启动器?也许其他人会举杯。我现在尝试与某人进行对话并选择创建联系人的快捷方式,我可以清楚地看到 toast 。我使用 Nova Launcher。
    猜你喜欢
    • 2014-07-16
    • 2011-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-02
    • 1970-01-01
    相关资源
    最近更新 更多