List of usage examples for android.content Intent EXTRA_SHORTCUT_ICON_RESOURCE
String EXTRA_SHORTCUT_ICON_RESOURCE
To view the source code for android.content Intent EXTRA_SHORTCUT_ICON_RESOURCE.
Click Source Link
From source file:Main.java
private static Drawable getShortcutIcon(Context context, Intent shortcutIntent) { if (!shortcutIntent.hasExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE)) { return null; }/* w w w. j ava 2s. c o m*/ try { Intent.ShortcutIconResource iconRes = shortcutIntent .getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE); Resources appRes = context.getPackageManager().getResourcesForApplication(iconRes.packageName); int resId = appRes.getIdentifier(iconRes.resourceName, null, null); return appRes.getDrawable(resId); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static void createShortcut(Context ctx, String shortCutName, int iconId, Intent presentIntent) { Intent shortcutIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT"); shortcutIntent.putExtra("duplicate", false); shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortCutName); shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(ctx, iconId)); shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, presentIntent); ctx.sendBroadcast(shortcutIntent);//from w ww.ja va2 s . co m }
From source file:Main.java
public static void createDeskShortCut(Context cxt, String shortCutName, int icon, Class<?> cls) { Intent shortcutIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT"); shortcutIntent.putExtra("duplicate", false); shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortCutName); Parcelable ico = Intent.ShortcutIconResource.fromContext(cxt.getApplicationContext(), icon); shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, ico); Intent intent = new Intent(cxt, cls); intent.setAction("android.intent.action.MAIN"); intent.addCategory("android.intent.category.LAUNCHER"); shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent); cxt.sendBroadcast(shortcutIntent);/*from w ww.jav a 2 s. c o m*/ }
From source file:MainActivity.java
public void createShortcut(View view) { Intent shortcutIntent = new Intent(this, MainActivity.class); shortcutIntent.setAction(Intent.ACTION_MAIN); Intent installIntent = new Intent(); installIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); installIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name)); installIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_launcher)); installIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); sendBroadcast(installIntent);//from ww w . j a v a 2 s .c o m }
From source file:at.tomtasche.reader.ui.activity.ShortcutActivity.java
@Override public DocumentLoader loadUri(Uri uri) { ShortcutIconResource icon = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon); Intent intent = new Intent(); Intent launchIntent = new Intent(this, MainActivity.class); launchIntent.setAction(Intent.ACTION_VIEW); launchIntent.setData(uri);/* www. ja v a2s . c o m*/ intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launchIntent); intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, uri.getLastPathSegment()); intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon); setResult(RESULT_OK, intent); finish(); return null; }
From source file:com.github.yuukis.businessmap.app.IncomingShortcutActivity.java
private void createShortcut(ContactsGroup group) { if (group == null) { setResult(RESULT_CANCELED, null); return;/*from w w w .ja v a 2 s. co m*/ } long groupId = group.getId(); String shortcutTitle = group.getTitle(); if (shortcutTitle.isEmpty()) { shortcutTitle = getString(R.string.app_name); } Intent shortcutIntent = new Intent(getApplicationContext(), MainActivity.class); shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); shortcutIntent.putExtra(MainActivity.KEY_CONTACTS_GROUP_ID, groupId); Intent intent = new Intent(); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); Parcelable iconResource = Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.ic_launcher); // ???????? intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource); // ?????????? intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortcutTitle); setResult(RESULT_OK, intent); }
From source file:cm.aptoide.ptdev.preferences.ManagerPreferences.java
public void createLauncherShortcut(Context context, int drawable) { //removeLauncherShortcut(context); Intent shortcutIntent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName()); Log.d("Aptoide-Shortcut", "Creating Intent"); final Intent intent = new Intent(); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, Aptoide.getConfiguration().getMarketName()); Parcelable iconResource;/* ww w .ja va 2s . c om*/ iconResource = Intent.ShortcutIconResource.fromContext(context, drawable); intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource); intent.putExtra("duplicate", false); intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); context.sendBroadcast(intent); }
From source file:com.pindroid.activity.ChooseTagShortcut.java
public void onTagSelected(String tag) { final Intent shortcutIntent = IntentHelper.ViewBookmarks(tag, username, null, this); final ShortcutIconResource iconResource = Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_shortcut);//from w ww . ja v a 2s. c o m final Intent intent = new Intent(); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, tag); intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource); setResult(RESULT_OK, intent); finish(); }
From source file:de.Maxr1998.xposed.maxlock.ui.MasterSwitchShortcutActivity.java
@SuppressLint("WorldReadableFiles") @Override//w w w . ja v a 2 s .co m public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getIntent().getBooleanExtra("LaunchOnly", false)) { // Launch Log.d("MaxLock", "Launching shortcut"); //noinspection deprecation prefsPackages = getSharedPreferences(Common.PREFS_PACKAGES, Context.MODE_WORLD_READABLE); if (prefsPackages.getBoolean(Common.MASTER_SWITCH_ON, true)) { setContentView(R.layout.activity_lock); Fragment frag = new LockFragment(); Bundle b = new Bundle(1); b.putString(Common.INTENT_EXTRAS_PKG_NAME, getString(R.string.unlock_master_switch)); frag.setArguments(b); getSupportFragmentManager().beginTransaction().replace(R.id.frame_container, frag).commit(); } else { prefsPackages.edit().putBoolean(Common.MASTER_SWITCH_ON, true).commit(); Toast.makeText(this, getString(R.string.toast_master_switch_on), Toast.LENGTH_LONG).show(); fireIntentAndFinish(); } } else { // Create shortcut Log.d("MaxLock", "Creating shortcut"); Intent shortcut = new Intent(this, MasterSwitchShortcutActivity.class); shortcut.putExtra("LaunchOnly", true); Intent install = new Intent(); install.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.toggle_master_switch)); install.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.mipmap.ic_launcher)); install.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcut); setResult(RESULT_OK, install); fireIntentAndFinish(); } }
From source file:com.jefftharris.passwdsafe.LauncherFileShortcuts.java
@Override public void openFile(Uri uri, String fileName) { if (itsIsDefaultFile || (uri != null)) { Intent openIntent = null;/* w ww .j av a 2 s .co m*/ if (uri != null) { openIntent = PasswdSafeUtil.createOpenIntent(uri, null); } Intent intent = new Intent(); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, openIntent); intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, fileName); intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_launcher_passwdsafe)); setResult(RESULT_OK, intent); } finish(); }