Valeh Ağayev
Valeh Ağayev

Reputation: 596

How to prevent toast message when creatin app icon on screen

I want to create app icon on phone screen and I do it but when I do it automatically app creates toast message, How to prevent this toast message when creating 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" />

Upvotes: 0

Views: 682

Answers (1)

android developer
android developer

Reputation: 116392

i think you can't , since the toast is shown by the launcher, which is a different app than yours.

i could be wrong though.

in any case, it's not your app that creates the toast, so it is highly unlikely that you can hide it.

Upvotes: 1

Related Questions