类android.content.Intent.ShortcutIconResource源码实例Demo

下面列出了怎么用android.content.Intent.ShortcutIconResource的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: LaunchEnr   文件: LauncherIcons.java
/**
 * 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;
}
 
源代码2 项目: LaunchEnr   文件: LoaderCursor.java
/**
 * 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;
}
 
源代码3 项目: letv   文件: a.java
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);
}
 
源代码4 项目: AndroidStudyDemo   文件: ShortCutUtil.java
/**
 * 为程序创建桌面快捷方式
 *
 * @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);
}
 
源代码5 项目: Trebuchet   文件: CursorIconInfo.java
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;
}
 
源代码6 项目: Utils   文件: ShortCutHelper.java
/**
 * 为程序创建桌面快捷方式
 *
 * @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);
}
 
源代码7 项目: AdDetector   文件: FloatFolder.java
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();
}
 
源代码8 项目: AndroidLinkup   文件: ShortcutUtil.java
/**
 * 为程序创建桌面快捷方式
 */
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);
}
 
源代码9 项目: zhangshangwuda   文件: CreateOneKeyWifi.java
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);
}
 
源代码10 项目: financisto   文件: PreferencesActivity.java
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;
}
 
源代码11 项目: letv   文件: UIs.java
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);
        }
    }
}
 
源代码12 项目: SecondScreen   文件: QuickLaunchActivity.java
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
}
 
源代码13 项目: zhangshangwuda   文件: CreateOneKeyWifi.java
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);
}
 
源代码14 项目: PowerFileExplorer   文件: ActivityPicker.java
/**
 * 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;
}
 
源代码15 项目: financisto   文件: PreferencesActivity.java
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);
}
 
源代码16 项目: emerald   文件: InstallShortcutReceiver.java
@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);
}
 
源代码17 项目: GravityBox   文件: ClearNotificationsShortcut.java
@Override
protected ShortcutIconResource getIconResource() {
    return ShortcutIconResource.fromContext(mContext, R.drawable.shortcut_notif_clear);
}
 
源代码18 项目: GravityBox   文件: AppLauncherShortcut.java
@Override
protected ShortcutIconResource getIconResource() {
    return ShortcutIconResource.fromContext(mContext, R.drawable.shortcut_app_launcher);
}
 
源代码19 项目: GravityBox   文件: ScreenshotShortcut.java
@Override
protected ShortcutIconResource getIconResource() {
    return ShortcutIconResource.fromContext(mContext, R.drawable.shortcut_screenshot);
}
 
源代码20 项目: GravityBox   文件: UnlockShortcut.java
@Override
protected ShortcutIconResource getIconResource() {
    return ShortcutIconResource.fromContext(mContext, R.drawable.ic_lockscreen_unlock);
}
 
源代码21 项目: GravityBox   文件: GoHomeShortcut.java
@Override
protected ShortcutIconResource getIconResource() {
    return ShortcutIconResource.fromContext(mContext, R.drawable.shortcut_home);
}
 
源代码22 项目: GravityBox   文件: KillAppShortcut.java
@Override
protected ShortcutIconResource getIconResource() {
    return ShortcutIconResource.fromContext(mContext, R.drawable.shortcut_kill_app);
}
 
源代码23 项目: GravityBox   文件: AMultiShortcut.java
@Override
protected ShortcutIconResource getIconResource() {
    return null;
}
 
源代码24 项目: GravityBox   文件: AMultiShortcut.java
public ShortcutIconResource getIconResource() {
    return ShortcutIconResource.fromContext(mContext, mIconResId);
}
 
源代码25 项目: GravityBox   文件: GoogleNowShortcut.java
@Override
protected ShortcutIconResource getIconResource() {
    return ShortcutIconResource.fromContext(mContext, R.drawable.shortcut_google_now);
}
 
源代码26 项目: GravityBox   文件: VolumePanelShortcut.java
@Override
protected ShortcutIconResource getIconResource() {
    return ShortcutIconResource.fromContext(mContext, R.drawable.shortcut_volume_panel);
}
 
源代码27 项目: GravityBox   文件: TorchShortcut.java
@Override
protected ShortcutIconResource getIconResource() {
    return ShortcutIconResource.fromContext(mContext, R.drawable.shortcut_torch);
}
 
源代码28 项目: GravityBox   文件: ScreenrecordShortcut.java
@Override
protected ShortcutIconResource getIconResource() {
    return ShortcutIconResource.fromContext(mContext, R.drawable.shortcut_screenrecord);
}
 
源代码29 项目: GravityBox   文件: RecentAppsShortcut.java
@Override
protected ShortcutIconResource getIconResource() {
    return ShortcutIconResource.fromContext(mContext, R.drawable.shortcut_recent_apps);
}
 
源代码30 项目: GravityBox   文件: LauncherDrawerShortcut.java
@Override
protected ShortcutIconResource getIconResource() {
    return ShortcutIconResource.fromContext(mContext, R.drawable.shortcut_launcher_drawer);
}
 
 类所在包
 类方法
 同包方法