0
The code below creates a shortcut on the device’s home screen, but by clicking on this shortcut, it returns me an error "The app is not installed" How to solve? I would like this mainactivity to be opened with a specific parameter, to trigger an event when opened by this created shortcut.
Below is the code used:
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
fabEmergencia.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
createShortCut();
return true;
}
});
private void createShortCut() {
Intent shortcutIntent = new Intent(activity,MainActivity.class);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "YourAppName");
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(activity, R.drawable.ic_launcher));
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
activity.sendBroadcast(addIntent);
}
The error happens, it creates the shortcut, but when clicking on this shortcut appears "The app is not installed"
– Henrique
Here with me it works normally! Your Internet is aimed at main class?
– viana
Yes, it is pointing to Mainactivity. But the button is also in Mainactivity. shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(this, Mainactivity.class));
– Henrique
I understood my mistake, the Auncher, is a splashactvity, she must be called. :/
– Henrique
@Henriquemendes exactly what I was going to say!
– viana