How to prevent toast message when creatin app icon on screen

点点圈 提交于 2019-12-10 19:04:27

问题


I want to create appp icon on phone screen and i do it but when i do it automaticli app creates toast message, How to prevent this toast message when creatin app icon or deleting icon on screen? Thanks.

That is code of how i do it

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();

Permissions for adding shortcuts

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

回答1:


Create hidden properties (i create CheckBox), after create shortcut set this true, then check parameter:

private void checkShortcut() {
        shortCut = GlobalClass.PREFS.getBoolean("ShortCut", false);
        if (shortCut == true) {
            //addShortcut();
        }
        else{
            remShortcut();
        }

    }



回答2:


No, sorry, there is no way to prevent a default system Toast from appearing.



来源:https://stackoverflow.com/questions/12345809/how-to-prevent-toast-message-when-creatin-app-icon-on-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!