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();**
Data encapsulation inside Android library project
Gradle. Resolved versions for compilation (x.x.x) and packaging (y.y.y) differ
Send inbox SMS to server via API
This application failed to start because it could not find or load the Qt platform plugin “android”
Drawing Image on Android
TextView real height with wrap_content single line
Firebase onDataChange method is not called even if the data is changed
Android AsyncTask + Handler, no data updated to Main Activity UI
Android - How to use XML feed from webpage?
android databinding: how to avoid onCheckedChanged triggered by programmatically
Android Support Library v7 PreferenceFragment Preference Headers
getAdapterPosition() is not found as a method
Android Simulator Date/Time is set to previous day
Why my APK is working just in Samsung phone?
Seekbar Controlling Soundpool, stops working
Android Signed APK showing as Unsigned APK when trying to upload to production