How to prevent toast message when creatin app icon

2019-07-04 02:20发布

问题:

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.