I have an app that allows you to create "shortcuts" in Home Screen. But can i detect if the "shortcuts" already exist, i didn't have to create it again. Thanks.
Go to Settings, then tap on “Display” then tap on “Full screen apps“. From there, turn on what apps you want to appear on your home screen. Go back to home screen after turning on all the apps you want icons for, scroll right to left, they should all be there.
I was having the same issue. I don't think its possible for you to tell if it's there, but I think what I used will work for you as well.
Simply uninstall the shortcut before you add it!
intent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(intent);
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(intent);
Just make sure you add the following to your manifest file.
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT"/>
I do not know whether it is possible to detect the shortcut or not, but instead of uninstalling and then installing, you can use the Extra field as
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, appName);
...
intent.putExtra("duplicate", false);
...
sendBroadcast(intent);
I think I found a good way to make sure the shortcut is not add more than once and also the Toast message to go away. Make a int or boolean (I used a int) and put the following in onResume:
if(shortcut != 1) //or shortcut == true
{
...(shortcut code)...
shortcut = 1;
savePref("shortcut", shortcut); //overriding method to save int's or booleans
}
If user delete's the user data then it will add another shortcut to the home screen but I can live with that since most users don't delete that kind of stuff anyway unless they are uninstalling the app. Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With