android


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();**

Related Links

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

Categories

HOME
uml
eclipse
apache-jena
twig
3d
fftw
jsf-2.2
devise
edge
yandex
data-visualization
dkim
windows-ce
intercom
android-7.0-nougat
symfony-console
production
delphi-xe5
simpleitk
visual-glitch
poedit
event-store
quantlib
tizen-tv
glib
nested-lists
navigator
reason
graphhopper
cd
projects-and-solutions
filesystemwatcher
xv6
trigonometry
dcmtk
avcapturedevice
memory-mapping
stylecop
snapchat
ovf
spring-integration-sftp
trojan
jqchart
flac
filenet
builtins
webjars
jboss-tools
synonym
dup
eigenvector
lz77
realsense
jaunt-api
concept-insights
jnlua
atan2
lazybones
microsoft-reporting
zen-cart
canalyzer
vacuum
apache-commons-daemon
omnifaces
grouping-sets
at-job
boost-program-options
post-commit-hook
file-not-found
qscrollarea
http-patch
mysql-error-1044
mvc-editor-templates
server-administration
resource-management
monotouch.dialog
jquery-blockui
garbage
predicatebuilder
floating-point-exceptions
node-redis
screen-size
mbeans
vs-android
interprocess
folding
application-verifier
fdf
int64

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App