Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect shortcut in Home screen

Tags:

android

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.

like image 454
user430926 Avatar asked Jan 12 '11 11:01

user430926


People also ask

Why are my shortcuts disappearing from my home screen?

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.


3 Answers

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"/>    
like image 64
tyler Avatar answered Oct 30 '22 15:10

tyler


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);
like image 8
Vasu Avatar answered Oct 30 '22 14:10

Vasu


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!

like image 1
abotrix Avatar answered Oct 30 '22 15:10

abotrix