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

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

Categories

HOME
spark-streaming
components
shiro
access
spring-data-mongodb
extjs4.2
syntaxnet
fabric.io
mxgraph
comsol
zerobrane
altera
scsi
mathprog
google-content-api
foreign-keys
solrcloud
asciidoctor-pdf
imagemap
named-entity-recognition
postscript
jboss6.x
fable-f#
motion-detection
pylons
appirater
comparable
ntp
panoramas
erb
gnat-gps
dynamic-jasper
xcode7.3
reactivekit
sim-card
ods
demo
mcustomscrollbar
plaintext
wmp
lpsolve
placeholder
show-hide
apache-directory
rfc3339
textsum
sonarlint-eclipse
mschart
x-ray
corruption
page-replacement
stdmap
sundials
payload
cmp
py2neo
google-photos
filenet
testrail
cronexpression
centrifuge
tinkerpop3
spring-cloud-feign
dup
xdoclet
shopping
jtwig
http-status-code-401
stream-processing
hadoop-partitioning
yajsw
grass
exim4
qbxml
lazybones
atoi
nutiteq
diff3
apache-spark-1.3
ghcjs
contrast
template-deduction
malformedurlexception
amslidemenu
android-usb
bin
mysql-error-1044
embedded-fonts
dtmf
ebay-lms
asdf
node-blade
pclzip
uimanageddocument
os.system
window-decoration
denied
diagrams
luajava
hbm2java
message-passing
openfaces
application-verifier
scrollbars
lxr
purepdf
idatareader

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App