private SharedPreferences appSettings;
appSettings = getSharedPreferences("com.veggies24x7.joizone", MODE_PRIVATE);
// Make sure you only run addShortcut() once, not to create duplicate shortcuts.
if(!appSettings.getBoolean("shortcut", false)) {
addShortcut();
}
private void addShortcut() {
//Adding shortcut for MainActivity
//on Home screen
Intent shortcutIntent = new Intent(getApplicationContext(),
SplashActivity.class);
shortcutIntent.setAction(Intent.ACTION_MAIN);
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Veggies24x7");
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(getApplicationContext(),
R.mipmap.ic_launcher));
addIntent.putExtra("duplicate", false); // Just create once
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(addIntent);
SharedPreferences.Editor prefEditor = appSettings.edit();
prefEditor.putBoolean("shortcut", true);
prefEditor.commit();
}
Manifest Code:
appSettings = getSharedPreferences("com.veggies24x7.joizone", MODE_PRIVATE);
// Make sure you only run addShortcut() once, not to create duplicate shortcuts.
if(!appSettings.getBoolean("shortcut", false)) {
addShortcut();
}
private void addShortcut() {
//Adding shortcut for MainActivity
//on Home screen
Intent shortcutIntent = new Intent(getApplicationContext(),
SplashActivity.class);
shortcutIntent.setAction(Intent.ACTION_MAIN);
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Veggies24x7");
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(getApplicationContext(),
R.mipmap.ic_launcher));
addIntent.putExtra("duplicate", false); // Just create once
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(addIntent);
SharedPreferences.Editor prefEditor = appSettings.edit();
prefEditor.putBoolean("shortcut", true);
prefEditor.commit();
}
Manifest Code:
No comments:
Post a Comment
Dharamart.blogspot.in