Example usage for android.content Intent EXTRA_SHORTCUT_ICON_RESOURCE

List of usage examples for android.content Intent EXTRA_SHORTCUT_ICON_RESOURCE

Introduction

In this page you can find the example usage for android.content Intent EXTRA_SHORTCUT_ICON_RESOURCE.

Prototype

String EXTRA_SHORTCUT_ICON_RESOURCE

To view the source code for android.content Intent EXTRA_SHORTCUT_ICON_RESOURCE.

Click Source Link

Document

The name of the extra used to define the icon, as a ShortcutIconResource, of a shortcut.

Usage

From source file:cn.whereyougo.framework.utils.PackageManagerUtil.java

/**
 * ????/*from ww  w  .j  a va2 s . co  m*/
 * 
 * @param mContext
 *            
 * @param TagClass
 *            ???
 * @param iconResId
 *            ??
 * @param iconName
 *            ??
 */
public static void addShortCut2Desktop(Context mContext, Class<?> TagClass, int iconResId, String iconName) {
    SharedPreferences sp = mContext.getSharedPreferences("appinfo", Context.MODE_PRIVATE);
    if (!sp.getBoolean("shortcut_flag_icon", false)) {
        sp.edit().putBoolean("shortcut_flag_icon", true).commit();
        LogUtil.d("shortcut", "first create successfull");
    } else {
        LogUtil.d("shortcut", "no created");
        return;
    }

    String ACTION_ADD_SHORTCUT = "com.android.launcher.action.INSTALL_SHORTCUT";
    Intent intent = new Intent();
    intent.setClass(mContext, TagClass);
    intent.setAction("android.intent.action.MAIN");
    intent.addCategory("android.intent.category.LAUNCHER");
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

    Intent addShortcut = new Intent(ACTION_ADD_SHORTCUT);
    Parcelable icon = Intent.ShortcutIconResource.fromContext(mContext, iconResId);// ???
    addShortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, iconName);// ??
    addShortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);// ??
    addShortcut.putExtra("duplicate", false);// ????
    addShortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);// ??

    mContext.sendBroadcast(addShortcut);// ??
}

From source file:dong.lan.tuyi.activity.SettingsFragment.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.feedback:
        startActivity(new Intent(getActivity(), FeedBackActivity.class));
        getActivity().overridePendingTransition(R.anim.slide_in_from_left, R.anim.slide_out_to_right);
        break;/*  ww  w.j  ava 2s .co  m*/
    case R.id.reset_lock:
        if (Config.isSetLock(getActivity()))
            Lock.locking(getActivity(), parent, Lock.RESETLOCK);
        else
            Show("?");
        break;
    case R.id.add_shortcut:
        Intent addIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
        Parcelable ioc = Intent.ShortcutIconResource.fromContext(getActivity(), R.drawable.logo);
        Intent clickIntent = new Intent(getActivity(), Welcome.class);
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getResources().getString(R.string.app_name));
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, ioc);
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, clickIntent);
        getActivity().sendBroadcast(addIntent);
        Show("????");
        break;
    case R.id.rl_switch_notification:
        if (iv_switch_open_notification.getVisibility() == View.VISIBLE) {
            iv_switch_open_notification.setVisibility(View.INVISIBLE);
            iv_switch_close_notification.setVisibility(View.VISIBLE);
            rl_switch_sound.setVisibility(View.GONE);
            rl_switch_vibrate.setVisibility(View.GONE);
            textview1.setVisibility(View.GONE);
            textview2.setVisibility(View.GONE);
            chatOptions.setNotificationEnable(false);
            EMChatManager.getInstance().setChatOptions(chatOptions);

            HXSDKHelper.getInstance().getModel().setSettingMsgNotification(false);
        } else {
            iv_switch_open_notification.setVisibility(View.VISIBLE);
            iv_switch_close_notification.setVisibility(View.INVISIBLE);
            rl_switch_sound.setVisibility(View.VISIBLE);
            rl_switch_vibrate.setVisibility(View.VISIBLE);
            textview1.setVisibility(View.VISIBLE);
            textview2.setVisibility(View.VISIBLE);
            chatOptions.setNotificationEnable(true);
            EMChatManager.getInstance().setChatOptions(chatOptions);
            HXSDKHelper.getInstance().getModel().setSettingMsgNotification(true);
        }
        break;
    case R.id.rl_switch_sound:
        if (iv_switch_open_sound.getVisibility() == View.VISIBLE) {
            iv_switch_open_sound.setVisibility(View.INVISIBLE);
            iv_switch_close_sound.setVisibility(View.VISIBLE);
            chatOptions.setNoticeBySound(false);
            EMChatManager.getInstance().setChatOptions(chatOptions);
            HXSDKHelper.getInstance().getModel().setSettingMsgSound(false);
        } else {
            iv_switch_open_sound.setVisibility(View.VISIBLE);
            iv_switch_close_sound.setVisibility(View.INVISIBLE);
            chatOptions.setNoticeBySound(true);
            EMChatManager.getInstance().setChatOptions(chatOptions);
            HXSDKHelper.getInstance().getModel().setSettingMsgSound(true);
        }
        break;
    case R.id.rl_switch_vibrate:
        if (iv_switch_open_vibrate.getVisibility() == View.VISIBLE) {
            iv_switch_open_vibrate.setVisibility(View.INVISIBLE);
            iv_switch_close_vibrate.setVisibility(View.VISIBLE);
            chatOptions.setNoticedByVibrate(false);
            EMChatManager.getInstance().setChatOptions(chatOptions);
            HXSDKHelper.getInstance().getModel().setSettingMsgVibrate(false);
        } else {
            iv_switch_open_vibrate.setVisibility(View.VISIBLE);
            iv_switch_close_vibrate.setVisibility(View.INVISIBLE);
            chatOptions.setNoticedByVibrate(true);
            EMChatManager.getInstance().setChatOptions(chatOptions);
            HXSDKHelper.getInstance().getModel().setSettingMsgVibrate(true);
        }
        break;

    case R.id.btn_logout: //
        logout();
        break;
    case R.id.ll_black_list:
        startActivity(new Intent(getActivity(), BlacklistActivity.class));
        break;
    case R.id.offline_map_tv:
        startActivity(new Intent(getActivity(), OfflineMapActivity.class));
        break;
    default:
        break;
    }

}

From source file:com.android.launcher4.InstallShortcutReceiver.java

public void onReceive(Context context, Intent data) {
    if (!ACTION_INSTALL_SHORTCUT.equals(data.getAction())) {
        return;//from   www  . j  a v  a2 s. c o  m
    }

    if (DBG)
        Log.d(TAG, "Got INSTALL_SHORTCUT: " + data.toUri(0));

    Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    if (intent == null) {
        return;
    }

    // This name is only used for comparisons and notifications, so fall back to activity name
    // if not supplied
    String name = ensureValidName(context, intent, data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME)).toString();
    Bitmap icon = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
    Intent.ShortcutIconResource iconResource = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);

    // Queue the item up for adding if launcher has not loaded properly yet
    LauncherAppState.setApplicationContext(context.getApplicationContext());
    LauncherAppState app = LauncherAppState.getInstance();
    boolean launcherNotLoaded = (app.getDynamicGrid() == null);

    PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(data, name, intent);
    info.icon = icon;
    info.iconResource = iconResource;

    String spKey = LauncherAppState.getSharedPreferencesKey();
    SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
    addToInstallQueue(sp, info);
    if (!mUseInstallQueue && !launcherNotLoaded) {
        flushInstallQueue(context);
    }
}

From source file:cc.flydev.launcher.InstallShortcutReceiver.java

public void onReceive(Context context, Intent data) {
    if (!ACTION_INSTALL_SHORTCUT.equals(data.getAction())) {
        return;// w w  w .  ja  v  a  2  s.  co m
    }

    if (DBG)
        Log.d(TAG, "Got INSTALL_SHORTCUT: " + data.toUri(0));

    Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    if (intent == null) {
        return;
    }
    // This name is only used for comparisons and notifications, so fall back to activity name
    // if not supplied
    String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
    if (name == null) {
        try {
            PackageManager pm = context.getPackageManager();
            ActivityInfo info = pm.getActivityInfo(intent.getComponent(), 0);
            name = info.loadLabel(pm).toString();
        } catch (PackageManager.NameNotFoundException nnfe) {
            return;
        }
    }
    Bitmap icon = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
    Intent.ShortcutIconResource iconResource = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);

    // Queue the item up for adding if launcher has not loaded properly yet
    LauncherAppState.setApplicationContext(context.getApplicationContext());
    LauncherAppState app = LauncherAppState.getInstance();
    boolean launcherNotLoaded = (app.getDynamicGrid() == null);

    PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(data, name, intent);
    info.icon = icon;
    info.iconResource = iconResource;

    String spKey = LauncherAppState.getSharedPreferencesKey();
    SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
    addToInstallQueue(sp, info);
    if (!mUseInstallQueue && !launcherNotLoaded) {
        flushInstallQueue(context);
    }
}

From source file:com.llf.android.launcher3.InstallShortcutReceiver.java

@Override
public void onReceive(Context context, Intent data) {
    if (!ACTION_INSTALL_SHORTCUT.equals(data.getAction())) {
        return;//from   w ww  . j a va  2 s .c o m
    }

    if (DBG)
        Log.d(TAG, "Got INSTALL_SHORTCUT: " + data.toUri(0));

    Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    if (intent == null) {
        return;
    }
    // This name is only used for comparisons and notifications, so fall
    // back to activity name
    // if not supplied
    String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
    if (name == null) {
        try {
            PackageManager pm = context.getPackageManager();
            ActivityInfo info = pm.getActivityInfo(intent.getComponent(), 0);
            name = info.loadLabel(pm).toString();
        } catch (PackageManager.NameNotFoundException nnfe) {
            return;
        }
    }
    Bitmap icon = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
    Intent.ShortcutIconResource iconResource = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);

    // Queue the item up for adding if launcher has not loaded properly yet
    LauncherAppState.setApplicationContext(context.getApplicationContext());
    LauncherAppState app = LauncherAppState.getInstance();
    boolean launcherNotLoaded = (app.getDynamicGrid() == null);

    PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(data, name, intent);
    info.icon = icon;
    info.iconResource = iconResource;

    String spKey = LauncherAppState.getSharedPreferencesKey();
    SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
    addToInstallQueue(sp, info);
    if (!mUseInstallQueue && !launcherNotLoaded) {
        flushInstallQueue(context);
    }
}

From source file:org.wso2.app.catalog.api.ApplicationManager.java

/**
 * Creates a webclip on the device home screen.
 *
 * @param url   - URL should be passed in as a String.
 * @param title - Title(Web app title) should be passed in as a String.
 */// w w  w .  jav  a 2 s  . c  om
public void manageWebAppBookmark(String url, String title, String operationType) throws AppCatalogException {
    final Intent bookmarkIntent = new Intent();
    final Intent actionIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    long urlHash = url.hashCode();
    long uniqueId = (urlHash << MAX_URL_HASH) | actionIntent.hashCode();

    actionIntent.putExtra(Browser.EXTRA_APPLICATION_ID, Long.toString(uniqueId));
    bookmarkIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, actionIntent);
    bookmarkIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
    bookmarkIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
            Intent.ShortcutIconResource.fromContext(context, R.drawable.ic_bookmark));
    if (operationType != null) {
        if (resources.getString(R.string.operation_install).equalsIgnoreCase(operationType)) {
            bookmarkIntent.setAction(resources.getString(R.string.application_package_launcher_install_action));
        } else if (resources.getString(R.string.operation_uninstall).equalsIgnoreCase(operationType)) {
            bookmarkIntent
                    .setAction(resources.getString(R.string.application_package_launcher_uninstall_action));
        } else {
            throw new AppCatalogException("Cannot create webclip due to invalid operation type.");
        }
    } else {
        bookmarkIntent.setAction(resources.getString(R.string.application_package_launcher_install_action));
    }
    context.sendBroadcast(bookmarkIntent);
}

From source file:library.artaris.cn.library.utils.SystemUtils.java

/**
 * ???//from w  w  w  . ja va  2s  .c o  m
 * @param context
 * @param shortCutName
 * @param icon
 * @param cls
 */
public static void createDeskShortCut(Context context, 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(context.getApplicationContext(), icon);
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, ico);
    Intent intent = new Intent(context, cls);
    intent.setAction("android.intent.action.MAIN");
    intent.addCategory("android.intent.category.LAUNCHER");
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
    context.sendBroadcast(shortcutIntent);
}

From source file:ru.orangesoftware.financisto2.activity.PreferencesActivity.java

private Intent createShortcutIntent(String activity, String shortcutName, ShortcutIconResource shortcutIcon,
        String action) {//  w w  w.j a v  a  2  s  .  c om
    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;
}

From source file:com.aidy.launcher3.ui.receiver.InstallShortcutReceiver.java

public void onReceive(Context context, Intent data) {
    if (!ACTION_INSTALL_SHORTCUT.equals(data.getAction())) {
        return;//w  w w.jav  a2  s  . c om
    }

    if (DBG)
        Log.d(TAG, "Got INSTALL_SHORTCUT: " + data.toUri(0));

    Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    if (intent == null) {
        return;
    }
    // This name is only used for comparisons and notifications, so fall
    // back to activity name
    // if not supplied
    String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
    if (name == null) {
        try {
            PackageManager pm = context.getPackageManager();
            ActivityInfo info = pm.getActivityInfo(intent.getComponent(), 0);
            name = info.loadLabel(pm).toString();
        } catch (PackageManager.NameNotFoundException nnfe) {
            return;
        }
    }
    Bitmap icon = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
    Intent.ShortcutIconResource iconResource = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);

    // Queue the item up for adding if launcher has not loaded properly yet
    LauncherAppState.setApplicationContext(context.getApplicationContext());
    LauncherAppState app = LauncherAppState.getInstance();
    boolean launcherNotLoaded = (app.getDynamicGrid() == null);

    PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(data, name, intent);
    info.icon = icon;
    info.iconResource = iconResource;

    String spKey = LauncherAppState.getSharedPreferencesKey();
    SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
    addToInstallQueue(sp, info);
    if (!mUseInstallQueue && !launcherNotLoaded) {
        flushInstallQueue(context);
    }
}

From source file:com.imagine.BaseActivity.java

void addViewShortcut(String name, String path) {
    Intent viewIntent = new Intent(this, BaseActivity.class);
    viewIntent.setAction(Intent.ACTION_VIEW);
    viewIntent.setData(Uri.parse("file://" + path));
    Intent launcherIntent = new Intent();
    launcherIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, viewIntent);
    launcherIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
    final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
    launcherIntent.putExtra(EXTRA_SHORTCUT_DUPLICATE, false);
    int icon = getResources().getIdentifier("icon", "drawable", getPackageName());
    launcherIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
            Intent.ShortcutIconResource.fromContext(this, icon));
    launcherIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    sendBroadcast(launcherIntent);/*from   w  ww.  j a  v a2s  .c om*/
}