How to determine if a home screen shortcut exists?
Is there a way to determine whether a particular home screen shortcut exists? My application installs a shortcut on the home screen at device startup time under certain conditions and I don't want duplicate shortcuts to appear. I also don't want Toast messages appearing saying "Shortcut created" or "Shortcut already exists" every single time the device boots. I've found an undocumented Intent Extra called EXTRA_SHORTCUT_DUPLICATE which will prevent duplicate shortcuts from being installed but the Launcher still displays the "Shortcut already exists" Toast message. I'd rather not rely on this undocumented Intent Extra if there is a supported technique for this.
isn't that kind of intrusive? Why not just add it once, and let the user decide if they want to keep it or not?
When your App create a shortcut,set "true" for a Boolean and store it in a storage(for example small file or sharedpreferences).And check it's value when your App try to create a shortcut.
**// Checking if ShortCut was already added SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE); boolean shortCutWasAlreadyAdded = sharedPreferences.getBoolean("PREF_KEY_SHORTCUT_ADDED", false); if (shortCutWasAlreadyAdded) return; Intent shortcutIntent = new Intent(getApplicationContext(), MainActivity.class); shortcutIntent.setAction(Intent.ACTION_MAIN); Intent addIntent = new Intent(); addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "SBM"); addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.ic_launcher)); addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); sendBroadcast(addIntent); // Remembering that ShortCut was already added SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putBoolean("PREF_KEY_SHORTCUT_ADDED", true); editor.commit();**
BroadcastReceiver does not trigger
Intent ACTION_CALL is not being intercepted by my application
Button “MyButton” is never used
Dynamically adding to listView in a fragment from mainActivity
Data does not reload automatically in a Fragment inside ViewPager
how to show dialog from my application for result (like google play game)
error in android studio log cat need help..open gl FBO not found
Android - Run/debug background service [duplicate]
Can findViewById(android.R.id.content) ever return null for Snackbars?
How to delete shadow of ball in opencv android
Swedish letters missing in google-vision Api response
Firebase Android Response code: 400
Set flags to interact with system overlay window?
Android values in Nexus 4 and 5X
Video streaming doesn't work on Android but works on iOS
What is MatOfPoint and List<MatOfPoint> in opencv android