I want to install the shortcut on the home screen when I install the application on any phone, I have tried a code for it and also it works perfect but it creates a new shortcut every time I start the application(If I start application 3 times then it creates the 3 shortcut on homescreen) please help me for this,
here is my code,
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addshortcut();
setContentView(R.layout.activity_splash);
ivsplash=(ImageView)findViewById(R.id.ivsplash);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent i = new Intent(Splash.this, Home.class);
startActivity(i);
finish();
}
},SPLASH_TIME_OUT);
}
private void addshortcut() {
// TODO Auto-generated method stub
Intent shortcutIntent = new Intent(getApplicationContext(),
Splash.class);
shortcutIntent.setAction(Intent.ACTION_MAIN);
Intent addIntent = new Intent();
addIntent
.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "anaxus");
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(getApplicationContext(),
R.drawable.applogo1));
addIntent
.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(addIntent);
}
thank you.