android.content.Intent.ShortcutIconResource Java Examples
The following examples show how to use
android.content.Intent.ShortcutIconResource.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LauncherIcons.java From LaunchEnr with GNU General Public License v3.0 | 6 votes |
/** * Returns a bitmap suitable for the all apps view. If the package or the resource do not * exist, it returns null. */ public static Bitmap createIconBitmap(ShortcutIconResource iconRes, Context context) { PackageManager packageManager = context.getPackageManager(); // the resource try { Resources resources = packageManager.getResourcesForApplication(iconRes.packageName); if (resources != null) { final int id = resources.getIdentifier(iconRes.resourceName, null, null); return createIconBitmap(resources.getDrawableForDensity( id, LauncherAppState.getIDP(context).fillResIconDpi, context.getTheme()), context); } } catch (Exception e) { // Icon not found. } return null; }
Example #2
Source File: CreateOneKeyWifi.java From zhangshangwuda with Apache License 2.0 | 6 votes |
private void addShortcut() { Intent shortcut = new Intent( "com.android.launcher.action.INSTALL_SHORTCUT"); // 快捷方式的名称 shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.Wifi_onekey)); shortcut.putExtra("duplicate", false); // 不允许重复创建 Intent shortcutIntent = new Intent(Intent.ACTION_MAIN); shortcutIntent.setClassName(this, OneKeyWifi.class.getName()); shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); // 快捷方式的图标 ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext( this, R.drawable.wifi_onekey_icon); shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes); sendBroadcast(shortcut); }
Example #3
Source File: ShortcutUtil.java From AndroidLinkup with GNU General Public License v2.0 | 6 votes |
/** * 为程序创建桌面快捷方式 */ public void addShortcut() { Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT"); // 快捷方式的名称 shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, ctx.getString(R.string.app_name)); // 不允许重复创建 shortcut.putExtra("duplicate", false); Intent shortcutIntent = new Intent(Intent.ACTION_MAIN); shortcutIntent.setClass(ctx, WelcomeActivity.class); shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); // 快捷方式的图标 ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(ctx, R.drawable.ic_launcher); shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes); ctx.sendBroadcast(shortcut); }
Example #4
Source File: FloatFolder.java From AdDetector with Apache License 2.0 | 6 votes |
private void setUpShortCut() { Intent shortcut = new Intent( "com.android.launcher.action.INSTALL_SHORTCUT"); shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, "baiduad"); shortcut.putExtra("duplicate", true); Intent shortcutIntent = new Intent(Intent.ACTION_MAIN); shortcutIntent.putExtra("tName", "baiduad"); shortcutIntent.setClassName("com.baidu.adfolder", "com.baidu.adfolder.FloatFolder"); shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext( this, R.drawable.ic_launcher); shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes); sendBroadcast(shortcut); Editor editor = sharedPreferences.edit(); editor.putBoolean(PREFERENCE_KEY_SHORTCUT_EXISTS, true); editor.commit(); }
Example #5
Source File: ShortCutHelper.java From Utils with Apache License 2.0 | 6 votes |
/** * 为程序创建桌面快捷方式 * * @param activity Activity * @param res res */ public static void addShortcut(Activity activity, int res) { Intent shortcut = new Intent( "com.android.launcher.action.INSTALL_SHORTCUT"); // 快捷方式的名称 shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, activity.getString(R.string.app_name)); shortcut.putExtra("duplicate", false); // 不允许重复创建 Intent shortcutIntent = new Intent(Intent.ACTION_MAIN); shortcutIntent.setClassName(activity, activity.getClass().getName()); shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); // 快捷方式的图标 ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext( activity, res); shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes); activity.sendBroadcast(shortcut); }
Example #6
Source File: CursorIconInfo.java From Trebuchet with GNU General Public License v3.0 | 6 votes |
public Bitmap loadIcon(Cursor c, ShortcutInfo info, Context context) { Bitmap icon = null; int iconType = c.getInt(iconTypeIndex); switch (iconType) { case LauncherSettings.Favorites.ICON_TYPE_RESOURCE: String packageName = c.getString(iconPackageIndex); String resourceName = c.getString(iconResourceIndex); if (!TextUtils.isEmpty(packageName) || !TextUtils.isEmpty(resourceName)) { info.iconResource = new ShortcutIconResource(); info.iconResource.packageName = packageName; info.iconResource.resourceName = resourceName; icon = Utilities.createIconBitmap(packageName, resourceName, context); } if (icon == null) { // Failed to load from resource, try loading from DB. icon = Utilities.createIconBitmap(c, iconIndex, context); } break; case LauncherSettings.Favorites.ICON_TYPE_BITMAP: icon = Utilities.createIconBitmap(c, iconIndex, context); info.customIcon = icon != null; break; } return icon; }
Example #7
Source File: ShortCutUtil.java From AndroidStudyDemo with GNU General Public License v2.0 | 6 votes |
/** * 为程序创建桌面快捷方式 * * @param activity Activity */ public static void addShortcut(Activity activity) { Intent shortcut = new Intent( "com.android.launcher.action.INSTALL_SHORTCUT"); // 快捷方式的名称 shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, activity.getString(R.string.app_name)); shortcut.putExtra("duplicate", false); // 不允许重复创建 Intent shortcutIntent = new Intent(Intent.ACTION_MAIN); shortcutIntent.setClassName(activity, activity.getClass().getName()); shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); // 快捷方式的图标 ShortcutIconResource iconRes = ShortcutIconResource.fromContext( activity, R.drawable.ic_launcher); shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes); activity.sendBroadcast(shortcut); }
Example #8
Source File: LoaderCursor.java From LaunchEnr with GNU General Public License v3.0 | 6 votes |
/** * Loads the icon from the cursor and updates the {@param info} if the icon is an app resource. */ private Bitmap loadIcon(ShortcutInfo info) { Bitmap icon = null; if (itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) { String packageName = getString(iconPackageIndex); String resourceName = getString(iconResourceIndex); if (!TextUtils.isEmpty(packageName) || !TextUtils.isEmpty(resourceName)) { info.iconResource = new ShortcutIconResource(); info.iconResource.packageName = packageName; info.iconResource.resourceName = resourceName; icon = LauncherIcons.createIconBitmap(info.iconResource, mContext); } } if (icon == null) { // Failed to load from resource, try loading from DB. byte[] data = getBlob(iconIndex); try { icon = LauncherIcons.createIconBitmap( BitmapFactory.decodeByteArray(data, 0, data.length), mContext); } catch (Exception e) { return null; } } return icon; }
Example #9
Source File: a.java From letv with Apache License 2.0 | 6 votes |
public static void a(Context context, String str, String str2, int i) { Uri parse = Uri.parse(str2); if (parse == null) { new StringBuilder(z[34]).append(str2); z.b(); return; } Parcelable intent = new Intent(z[23], parse); intent.setFlags(335544320); Parcelable fromContext = ShortcutIconResource.fromContext(context, i); Intent intent2 = new Intent(z[30]); intent2.putExtra(z[33], false); intent2.putExtra(z[35], str); intent2.putExtra(z[32], intent); intent2.putExtra(z[31], fromContext); context.sendBroadcast(intent2); }
Example #10
Source File: CreateOneKeyWifi.java From zhangshangwuda with Apache License 2.0 | 5 votes |
void createShortCut() { Intent shortcutIntent = new Intent(Intent.ACTION_MAIN); shortcutIntent.setClass(this, OneKeyWifi.class); Intent intent = new Intent(); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.Wifi_onekey)); Parcelable shortIcon = Intent.ShortcutIconResource.fromContext(this, R.drawable.wifi_onekey_icon); intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortIcon); setResult(RESULT_OK, intent); }
Example #11
Source File: QuickLaunchActivity.java From SecondScreen with Apache License 2.0 | 5 votes |
private void quickLaunchProfile(String filename) { // The meat of our shortcut Intent shortcutIntent = new Intent (this, QuickLaunchActivity.class); shortcutIntent.setAction(Intent.ACTION_MAIN); shortcutIntent.putExtra(U.NAME, filename); shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); ShortcutIconResource iconResource = Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_launcher); // The result we are passing back from this activity Intent intent = new Intent(); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource); if(filename.equals("turn_off")) intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getResources().getStringArray(R.array.pref_notification_action_list)[0]); else { try { intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, U.getProfileTitle(this, filename)); } catch (IOException e) { U.showToast(this, R.string.error_loading_list); } } setResult(RESULT_OK, intent); finish(); // Must call finish for result to be returned immediately }
Example #12
Source File: PreferencesActivity.java From financisto with GNU General Public License v2.0 | 5 votes |
private Intent createShortcutIntent(String activity, String shortcutName, ShortcutIconResource shortcutIcon, String action) { Intent shortcutIntent = new Intent(); shortcutIntent.setComponent(new ComponentName(this.getPackageName(), activity)); shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); Intent intent = new Intent(); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortcutName); intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcon); intent.setAction(action); return intent; }
Example #13
Source File: UIs.java From letv with Apache License 2.0 | 5 votes |
public static void createShortCut(Context context) { if (context != null && PreferencesManager.getInstance().getShortcut()) { PreferencesManager.getInstance().setShortcut(false); if (!hasShortcut()) { Intent shortcutintent = new Intent(ApkConstant.ACTION_INSTALL_SHORTCUT); shortcutintent.putExtra("duplicate", false); shortcutintent.putExtra("android.intent.extra.shortcut.NAME", context.getString(2131099758)); shortcutintent.putExtra("android.intent.extra.shortcut.ICON_RESOURCE", ShortcutIconResource.fromContext(context.getApplicationContext(), 2130838438)); shortcutintent.putExtra("android.intent.extra.shortcut.INTENT", new Intent(context.getApplicationContext(), SplashActivity.class)); context.sendBroadcast(shortcutintent); } } }
Example #14
Source File: LauncherDrawerShortcut.java From GravityBox with Apache License 2.0 | 4 votes |
@Override protected ShortcutIconResource getIconResource() { return ShortcutIconResource.fromContext(mContext, R.drawable.shortcut_launcher_drawer); }
Example #15
Source File: ActivityPicker.java From PowerFileExplorer with GNU General Public License v3.0 | 4 votes |
/** * Build and return list of items to be shown in dialog. Default * implementation mixes activities matching {@link #mBaseIntent} from * {@link #putIntentItems(Intent, List)} with any injected items from * {@link Intent#EXTRA_SHORTCUT_NAME}. Override this method in subclasses to * change the items shown. */ protected List<PickAdapter.Item> getItems() { PackageManager packageManager = getPackageManager(); List<PickAdapter.Item> items = new ArrayList<PickAdapter.Item>(); // Add any injected pick items final Intent intent = getIntent(); ArrayList<String> labels = intent.getStringArrayListExtra(Intent.EXTRA_SHORTCUT_NAME); ArrayList<ShortcutIconResource> icons = intent.getParcelableArrayListExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE); if (labels != null && icons != null && labels.size() == icons.size()) { for (int i = 0; i < labels.size(); i++) { String label = labels.get(i); Drawable icon = null; try { // Try loading icon from requested package ShortcutIconResource iconResource = icons.get(i); Resources res = packageManager.getResourcesForApplication( iconResource.packageName); icon = res.getDrawable(res.getIdentifier( iconResource.resourceName, null, null)); } catch (NameNotFoundException e) { // Ignore } items.add(new PickAdapter.Item(this, label, icon)); } } // Add any intent items if base was given if (mBaseIntent != null) { putIntentItems(mBaseIntent, items); } if ( items.size() == 0 ){ return null; } return items; }
Example #16
Source File: PreferencesActivity.java From financisto with GNU General Public License v2.0 | 4 votes |
private void addShortcut(String activity, int nameId, int iconId) { Intent intent = createShortcutIntent(activity, getString(nameId), Intent.ShortcutIconResource.fromContext(this, iconId), "com.android.launcher.action.INSTALL_SHORTCUT"); sendBroadcast(intent); }
Example #17
Source File: ActivityPicker.java From JotaTextEditor with Apache License 2.0 | 4 votes |
/** * Build and return list of items to be shown in dialog. Default * implementation mixes activities matching {@link #mBaseIntent} from * {@link #putIntentItems(Intent, List)} with any injected items from * {@link Intent#EXTRA_SHORTCUT_NAME}. Override this method in subclasses to * change the items shown. */ protected List<PickAdapter.Item> getItems() { PackageManager packageManager = getPackageManager(); List<PickAdapter.Item> items = new ArrayList<PickAdapter.Item>(); // Add any injected pick items final Intent intent = getIntent(); ArrayList<String> labels = intent.getStringArrayListExtra(Intent.EXTRA_SHORTCUT_NAME); ArrayList<ShortcutIconResource> icons = intent.getParcelableArrayListExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE); if (labels != null && icons != null && labels.size() == icons.size()) { for (int i = 0; i < labels.size(); i++) { String label = labels.get(i); Drawable icon = null; try { // Try loading icon from requested package ShortcutIconResource iconResource = icons.get(i); Resources res = packageManager.getResourcesForApplication( iconResource.packageName); icon = res.getDrawable(res.getIdentifier( iconResource.resourceName, null, null)); } catch (NameNotFoundException e) { // Ignore } items.add(new PickAdapter.Item(this, label, icon)); } } // Add any intent items if base was given if (mBaseIntent != null) { putIntentItems(mBaseIntent, items); } if ( items.size() == 0 ){ return null; } return items; }
Example #18
Source File: ShortCutUtils.java From BigApp_Discuz_Android with Apache License 2.0 | 4 votes |
/** * 为程序创建桌面快捷方式 */ public static void addShortcut(Context context, String name, int resIconId, Intent intent) { final Intent addIntent = new Intent( "com.android.launcher.action.INSTALL_SHORTCUT"); final Parcelable icon = Intent.ShortcutIconResource.fromContext( context, resIconId); // 获取快捷键的图标 addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);// 快捷方式的标题 addIntent.putExtra("duplicate", false); // 不允许重复创建 addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);// 快捷方式的图标 //创建一键锁屏图标 // Intent i = new Intent(); // i.setClass(context.getApplicationContext(), OneKeyLockActivity.class); // ShortCutUtils.addShortcut(context, "锁屏", // R.drawable.composer_sleep, i); // PackageManager pm = context.getPackageManager(); // Intent i = pm.getLaunchIntentForPackage(context.getPackageName()); addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);// 快捷方式的动作 context.sendBroadcast(addIntent); // Intent shortcut = new Intent( // "com.android.launcher.action.INSTALL_SHORTCUT"); // // // 快捷方式的名称 // shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, name); // shortcut.putExtra("duplicate", false); // 不允许重复创建 // // /**************************** 此方法已失效 *************************/ // // ComponentName comp = new ComponentName(this.getPackageName(), // // "."+this.getLocalClassName()); // // shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new // // Intent(Intent.ACTION_MAIN).setComponent(comp)); // /****************************** end *******************************/ // // Intent shortcutIntent = new Intent(Intent.ACTION_MAIN); // // shortcutIntent.setClassName(context, // context.getClass().getName()); // // shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); // shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);// 快捷方式的动作 // // 快捷方式的图标 // ShortcutIconResource iconRes = // Intent.ShortcutIconResource.fromContext( // context, resIconId); // shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes); // // context.sendBroadcast(shortcut); }
Example #19
Source File: ShowPowerMenuShortcut.java From GravityBox with Apache License 2.0 | 4 votes |
@Override protected ShortcutIconResource getIconResource() { return ShortcutIconResource.fromContext(mContext, R.drawable.shortcut_power_menu); }
Example #20
Source File: SwitchAppShortcut.java From GravityBox with Apache License 2.0 | 4 votes |
@Override protected ShortcutIconResource getIconResource() { return ShortcutIconResource.fromContext(mContext, R.drawable.shortcut_previous_app); }
Example #21
Source File: SleepShortcut.java From GravityBox with Apache License 2.0 | 4 votes |
@Override protected ShortcutIconResource getIconResource() { return ShortcutIconResource.fromContext(mContext, R.drawable.shortcut_sleep); }
Example #22
Source File: InstallShortcutReceiver.java From emerald with GNU General Public License v3.0 | 4 votes |
@Override @SuppressWarnings("deprecation") public void onReceive(Context context, Intent intent) { Intent shortcutIntent = intent.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT); String uri = shortcutIntent.toUri(0); if (DatabaseHelper.hasShortcut(context, uri) || isAppLink(uri)) { return; } if (shortcutIntent.getAction() == null) { shortcutIntent.setAction(Intent.ACTION_VIEW); } String name = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME); Bitmap icon = intent.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON); String packageName = null; String resourceName = null; ContentValues values = new ContentValues(); if (icon == null) { ShortcutIconResource resource = intent.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE); if (resource != null) { packageName = resource.packageName; resourceName = resource.resourceName; PackageManager pm = context.getPackageManager(); try { Resources res = pm.getResourcesForApplication(packageName); int id = res.getIdentifier(resourceName, "png", packageName); Drawable d = res.getDrawable(id); icon = ((BitmapDrawable) d).getBitmap(); } catch (Exception e) { Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show(); } } else { //invalid shortcut return; } } ByteArrayOutputStream out = new ByteArrayOutputStream(); icon.compress(CompressFormat.PNG, 100, out); values.put("icon", out.toString()); saveIcon(context, uri, icon); values.put("name", name); values.put("uri", uri); values.put("package", packageName); values.put("resource", resourceName); values.put("categories", ""); DatabaseHelper.insertShortcut(context, values); }
Example #23
Source File: RecentAppsShortcut.java From GravityBox with Apache License 2.0 | 4 votes |
@Override protected ShortcutIconResource getIconResource() { return ShortcutIconResource.fromContext(mContext, R.drawable.shortcut_recent_apps); }
Example #24
Source File: ScreenrecordShortcut.java From GravityBox with Apache License 2.0 | 4 votes |
@Override protected ShortcutIconResource getIconResource() { return ShortcutIconResource.fromContext(mContext, R.drawable.shortcut_screenrecord); }
Example #25
Source File: TorchShortcut.java From GravityBox with Apache License 2.0 | 4 votes |
@Override protected ShortcutIconResource getIconResource() { return ShortcutIconResource.fromContext(mContext, R.drawable.shortcut_torch); }
Example #26
Source File: VolumePanelShortcut.java From GravityBox with Apache License 2.0 | 4 votes |
@Override protected ShortcutIconResource getIconResource() { return ShortcutIconResource.fromContext(mContext, R.drawable.shortcut_volume_panel); }
Example #27
Source File: GoogleNowShortcut.java From GravityBox with Apache License 2.0 | 4 votes |
@Override protected ShortcutIconResource getIconResource() { return ShortcutIconResource.fromContext(mContext, R.drawable.shortcut_google_now); }
Example #28
Source File: AMultiShortcut.java From GravityBox with Apache License 2.0 | 4 votes |
public ShortcutIconResource getIconResource() { return ShortcutIconResource.fromContext(mContext, mIconResId); }
Example #29
Source File: AMultiShortcut.java From GravityBox with Apache License 2.0 | 4 votes |
@Override protected ShortcutIconResource getIconResource() { return null; }
Example #30
Source File: KillAppShortcut.java From GravityBox with Apache License 2.0 | 4 votes |
@Override protected ShortcutIconResource getIconResource() { return ShortcutIconResource.fromContext(mContext, R.drawable.shortcut_kill_app); }