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:com.lee.sdk.utils.Utils.java

/**
 * ????//from ww w  .  j  ava2 s  .  c o  m
 * 
 * @param activity ?Activity???
 * @param nameId ????
 * @param iconId ??
 * @param appendFlags ????IntentFlag
 */
public static void addShortcut(Activity activity, int nameId, int iconId, int appendFlags) {
    Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");

    // ????
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, activity.getString(nameId));
    shortcut.putExtra("duplicate", false); // ????

    // ?Activity???
    ComponentName comp = new ComponentName(activity.getPackageName(), activity.getClass().getName());
    Intent intent = new Intent(Intent.ACTION_MAIN).setComponent(comp);
    if (appendFlags != 0) {
        intent.addFlags(appendFlags);
    }
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);

    // ??
    ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(activity, iconId);
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);

    activity.sendBroadcast(shortcut);
}

From source file:com.metinkale.prayerapp.BaseActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (App.getContext() == null) {
        App.setContext(this);
    }//from www  .  jav a  2  s .  c om

    if (Intent.ACTION_CREATE_SHORTCUT.equals(getIntent().getAction())) {
        int id = R.mipmap.ic_launcher;
        switch (mNavPos) {
        case 1:
            id = R.mipmap.ic_compass;
            break;
        case 2:
            id = R.mipmap.ic_names;
            break;
        case 3:
            id = R.mipmap.ic_calendar;
            break;
        case 4:
            id = R.mipmap.ic_tesbihat;
            break;
        case 7:
            id = R.mipmap.ic_zikr;
            break;
        }

        Intent.ShortcutIconResource icon = Intent.ShortcutIconResource.fromContext(this, id);

        Intent intent = new Intent();
        Intent launchIntent = new Intent(this, getClass());
        launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        launchIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        launchIntent.putExtra("duplicate", false);

        intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launchIntent);
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getResources().getStringArray(R.array.dropdown)[mNavPos]);
        intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);

        setResult(RESULT_OK, intent);
        finish();
    }

    if (!Utils.askLang(this)) {
        Utils.init(this);
        Changelog.start(this);
    }

}

From source file:kinsleykajiva.co.zw.cutstudentapp.Settinngs.java

private void addShortcut() {

    Intent shortcutIntent = new Intent(getApplicationContext(), Settinngs.class);

    shortcutIntent.setAction(Intent.ACTION_MAIN);

    Intent addIntent = new Intent();
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "C.U.T Student");
    //addIntent.putExtra("duplicate", false);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
            Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.logo));

    addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    getApplicationContext().sendBroadcast(addIntent);
}

From source file:io.github.runassudo.ptoffline.fragments.SettingsFragment.java

@Override
public void onCreatePreferences(Bundle savedInstanceState, String s) {
    // Load the preferences from an XML resource
    addPreferencesFromResource(R.xml.preferences);

    TransportNetwork network = Preferences.getTransportNetwork(getActivity());

    // Fill in current home location if available
    network_pref = findPreference("pref_key_network");
    if (network != null)
        network_pref.setSummary(network.getName());

    network_pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override//  w ww . j a  v  a  2s  .c o m
        public boolean onPreferenceClick(Preference preference) {
            Intent intent = new Intent(getActivity(), PickNetworkProviderActivity.class);

            //            View view = preference.getView(null, null);
            View view = getView();
            if (view != null)
                view = view.findFocus();

            ActivityOptionsCompat options = ActivityOptionsCompat.makeScaleUpAnimation(view, (int) view.getX(),
                    (int) view.getY(), 0, 0);
            ActivityCompat.startActivityForResult(getActivity(), intent, MainActivity.CHANGED_NETWORK_PROVIDER,
                    options.toBundle());

            return true;
        }
    });

    home = findPreference("pref_key_home");
    home.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        public boolean onPreferenceClick(Preference preference) {
            // show home picker dialog
            HomePickerDialogFragment setHomeFragment = HomePickerDialogFragment.newInstance();
            setHomeFragment.setOnHomeChangedListener(SettingsFragment.this);
            FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
            setHomeFragment.show(ft, HomePickerDialogFragment.TAG);

            return true;
        }
    });

    // Fill in current home location if available
    if (network != null)
        setHome(null);

    quickhome = findPreference("pref_key_create_quickhome_shortcut");
    quickhome.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        public boolean onPreferenceClick(Preference preference) {
            // create launcher shortcut
            Intent addIntent = new Intent();
            addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, TransportrUtils.getShortcutIntent(getContext()));
            addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.widget_name_quickhome));
            addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                    Intent.ShortcutIconResource.fromContext(getContext(), R.drawable.ic_quickhome_widget));
            addIntent.putExtra("duplicate", false);
            addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
            getContext().sendBroadcast(addIntent);

            // switch to home-screen to let the user see the new shortcut
            Intent startMain = new Intent(Intent.ACTION_MAIN);
            startMain.addCategory(Intent.CATEGORY_HOME);
            startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(startMain);

            return true;
        }
    });
}

From source file:de.grobox.liberario.settings.SettingsFragment.java

@Override
public void onCreatePreferences(Bundle savedInstanceState, String s) {
    // Load the preferences from an XML resource
    addPreferencesFromResource(R.xml.preferences);

    TransportNetwork network = Preferences.getTransportNetwork(getActivity());

    // Fill in current home location if available
    network_pref = findPreference("pref_key_network");
    if (network != null)
        network_pref.setSummary(network.getName(getContext()));

    network_pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override//from   ww w  .j a  v  a 2s . co m
        public boolean onPreferenceClick(Preference preference) {
            Intent intent = new Intent(getActivity(), PickTransportNetworkActivity.class);
            View view = getView();
            if (view != null)
                view = view.findFocus();

            ActivityOptionsCompat options = ActivityOptionsCompat.makeScaleUpAnimation(view, (int) view.getX(),
                    (int) view.getY(), 0, 0);
            ActivityCompat.startActivityForResult(getActivity(), intent, REQUEST_NETWORK_PROVIDER_CHANGE,
                    options.toBundle());
            return true;
        }
    });

    // TODO remove from here
    home = findPreference("pref_key_home");
    home.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        public boolean onPreferenceClick(Preference preference) {
            // show home picker dialog
            HomePickerDialogFragment setHomeFragment = HomePickerDialogFragment.newInstance();
            FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
            setHomeFragment.show(ft, HomePickerDialogFragment.TAG);

            return true;
        }
    });
    // Fill in current home location if available
    if (network != null)
        setHome(null);

    quickhome = findPreference("pref_key_create_quickhome_shortcut");
    quickhome.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        public boolean onPreferenceClick(Preference preference) {
            // create launcher shortcut
            Intent addIntent = new Intent();
            addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, TransportrUtils.getShortcutIntent(getContext()));
            addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.widget_name_quickhome));
            addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                    Intent.ShortcutIconResource.fromContext(getContext(), R.drawable.ic_quickhome_widget));
            addIntent.putExtra("duplicate", false);
            addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
            getContext().sendBroadcast(addIntent);

            // switch to home-screen to let the user see the new shortcut
            Intent startMain = new Intent(Intent.ACTION_MAIN);
            startMain.addCategory(Intent.CATEGORY_HOME);
            startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(startMain);

            return true;
        }
    });
}

From source file:com.andernity.launcher2.InstallShortcutReceiver.java

private static ArrayList<PendingInstallShortcutInfo> getAndClearInstallQueue(SharedPreferences sharedPrefs) {
    synchronized (sLock) {
        Set<String> strings = sharedPrefs.getStringSet(APPS_PENDING_INSTALL, null);
        if (strings == null) {
            return new ArrayList<PendingInstallShortcutInfo>();
        }/*from w  w  w  .ja va  2s. c o m*/
        ArrayList<PendingInstallShortcutInfo> infos = new ArrayList<PendingInstallShortcutInfo>();
        for (String json : strings) {
            try {
                JSONObject object = (JSONObject) new JSONTokener(json).nextValue();
                Intent data = Intent.parseUri(object.getString(DATA_INTENT_KEY), 0);
                Intent launchIntent = Intent.parseUri(object.getString(LAUNCH_INTENT_KEY), 0);
                String name = object.getString(NAME_KEY);
                String iconBase64 = object.optString(ICON_KEY);
                String iconResourceName = object.optString(ICON_RESOURCE_NAME_KEY);
                String iconResourcePackageName = object.optString(ICON_RESOURCE_PACKAGE_NAME_KEY);
                if (iconBase64 != null && !iconBase64.isEmpty()) {
                    byte[] iconArray = Base64.decode(iconBase64, Base64.DEFAULT);
                    Bitmap b = BitmapFactory.decodeByteArray(iconArray, 0, iconArray.length);
                    data.putExtra(Intent.EXTRA_SHORTCUT_ICON, b);
                } else if (iconResourceName != null && !iconResourceName.isEmpty()) {
                    Intent.ShortcutIconResource iconResource = new Intent.ShortcutIconResource();
                    iconResource.resourceName = iconResourceName;
                    iconResource.packageName = iconResourcePackageName;
                    data.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
                }
                data.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launchIntent);
                PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(data, name, launchIntent);
                infos.add(info);
            } catch (org.json.JSONException e) {
                Log.d("InstallShortcutReceiver", "Exception reading shortcut to add: " + e);
            } catch (java.net.URISyntaxException e) {
                Log.d("InstallShortcutReceiver", "Exception reading shortcut to add: " + e);
            }
        }
        sharedPrefs.edit().putStringSet(APPS_PENDING_INSTALL, new HashSet<String>()).commit();
        return infos;
    }
}

From source file:com.markupartist.sthlmtraveling.SearchDeparturesFragment.java

private void onCreateShortCut(Site stop) {
    // Setup the intent to be launched
    Intent shortcutIntent = new Intent(getActivity().getApplicationContext(),
            DeparturesShortcutProxyActivity.class);
    shortcutIntent.setAction(Intent.ACTION_VIEW);
    shortcutIntent.putExtra(DeparturesActivity.EXTRA_SITE_NAME, stop.getName());
    shortcutIntent.putExtra(DeparturesActivity.EXTRA_SITE_ID, stop.getId());
    shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    // Then, set up the container intent (the response to the caller)
    Intent intent = new Intent();
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, stop.getName());
    Parcelable iconResource = Intent.ShortcutIconResource.fromContext(getActivity(),
            R.drawable.shortcut_departures);
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);

    // Now, return the result to the launcher
    getActivity().setResult(Activity.RESULT_OK, intent);
    getActivity().finish();/*from w  w  w  .ja  va  2s. co m*/
}

From source file:com.fvd.nimbus.MainActivity.java

public static void createShortcut(Context context) {

    Intent shortcutIntent = new Intent(context, MainActivity.class);
    shortcutIntent.setAction(Intent.ACTION_MAIN);
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
    Intent addIntent = new Intent();
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Nimbus Clipper");
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
            Intent.ShortcutIconResource.fromContext(context, R.drawable.app_icon));
    addIntent.putExtra("duplicate", false);
    addIntent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
    context.sendBroadcast(addIntent);/* w  ww .  j  ava2 s  .  c  om*/
    addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    context.sendBroadcast(addIntent);
}

From source file:com.marlonjones.voidlauncher.InstallShortcutReceiver.java

/**
 * Verifies the intent and creates a {@link PendingInstallShortcutInfo}
 *//*from w  w  w.j  a  va  2 s. co  m*/
private static PendingInstallShortcutInfo createPendingInfo(Context context, Intent data) {
    if (!isValidExtraType(data, Intent.EXTRA_SHORTCUT_INTENT, Intent.class)
            || !(isValidExtraType(data, Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.class))
            || !(isValidExtraType(data, Intent.EXTRA_SHORTCUT_ICON, Bitmap.class))) {

        if (DBG)
            Log.e(TAG, "Invalid install shortcut intent");
        return null;
    }

    PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(data, context);
    if (info.launchIntent == null || info.label == null) {
        if (DBG)
            Log.e(TAG, "Invalid install shortcut intent");
        return null;
    }

    return convertToLauncherActivityIfPossible(info);
}

From source file:com.android.music.PlaylistBrowserFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    View view = inflater.inflate(R.layout.media_picker_activity, null);

    final Intent intent = getActivity().getIntent();
    final String action = intent.getAction();
    if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) {
        mCreateShortcut = true;// w  w w . j  a  va 2 s .c o  m
    }

    getActivity().setVolumeControlStream(AudioManager.STREAM_MUSIC);
    mToken = MusicUtils.bindToService(getActivity(), new ServiceConnection() {
        public void onServiceConnected(ComponentName classname, IBinder obj) {
            if (Intent.ACTION_VIEW.equals(action)) {
                Bundle b = intent.getExtras();
                if (b == null) {
                    Log.w(TAG, "Unexpected:getExtras() returns null.");
                } else {
                    try {
                        long id = Long.parseLong(b.getString("playlist"));
                        if (id == RECENTLY_ADDED_PLAYLIST) {
                            playRecentlyAdded();
                        } else if (id == PODCASTS_PLAYLIST) {
                            playPodcasts();
                        } else if (id == ALL_SONGS_PLAYLIST) {
                            long[] list = MusicUtils.getAllSongs(getActivity());
                            if (list != null) {
                                MusicUtils.playAll(getActivity(), list, 0);
                            }
                        } else {
                            MusicUtils.playPlaylist(getActivity(), id);
                        }
                    } catch (NumberFormatException e) {
                        Log.w(TAG, "Playlist id missing or broken");
                    }
                }
                getActivity().finish();
                return;
            }
            MusicUtils.updateNowPlaying(getActivity());
        }

        public void onServiceDisconnected(ComponentName classname) {
        }

    });

    IntentFilter f = new IntentFilter();
    f.addAction(Intent.ACTION_MEDIA_SCANNER_STARTED);
    f.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED);
    f.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
    f.addDataScheme("file");
    getActivity().registerReceiver(mScanListener, f);

    lv = (ListView) view.findViewById(android.R.id.list);
    lv.setOnCreateContextMenuListener(this);
    lv.setTextFilterEnabled(true);
    lv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // TODO Auto-generated method stub
            if (mCreateShortcut) {
                final Intent shortcut = new Intent();
                shortcut.setAction(Intent.ACTION_VIEW);
                shortcut.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/playlist");
                shortcut.putExtra("playlist", String.valueOf(id));

                final Intent intent = new Intent();
                intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcut);
                intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
                        ((TextView) view.findViewById(R.id.line1)).getText());
                intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource
                        .fromContext(getActivity(), R.drawable.ic_launcher_shortcut_music_playlist));

                getActivity().setResult(getActivity().RESULT_OK, intent);
                getActivity().finish();
                return;
            }
            if (id == RECENTLY_ADDED_PLAYLIST) {
                Intent intent = new Intent(Intent.ACTION_PICK);
                intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track");
                intent.putExtra("playlist", "recentlyadded");
                startActivity(intent);
            } else if (id == PODCASTS_PLAYLIST) {
                Intent intent = new Intent(Intent.ACTION_PICK);
                intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track");
                intent.putExtra("playlist", "podcasts");
                startActivity(intent);
            } else {
                Intent intent = new Intent(Intent.ACTION_EDIT);
                intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track");
                intent.putExtra("playlist", Long.valueOf(id).toString());
                startActivity(intent);
            }

        }
    });

    mAdapter = (PlaylistListAdapter) getActivity().getLastNonConfigurationInstance();
    if (mAdapter == null) {
        //Log.i("@@@", "starting query");
        mAdapter = new PlaylistListAdapter(getActivity().getApplication(), this, R.layout.track_list_item,
                mPlaylistCursor, new String[] { MediaStore.Audio.Playlists.NAME },
                new int[] { android.R.id.text1 });
        lv.setAdapter(mAdapter);
        //setTitle(R.string.working_playlists);
        getPlaylistCursor(mAdapter.getQueryHandler(), null);
    } else {
        mAdapter.setActivity(this);
        lv.setAdapter(mAdapter);
        mPlaylistCursor = mAdapter.getCursor();
        // If mPlaylistCursor is null, this can be because it doesn't have
        // a cursor yet (because the initial query that sets its cursor
        // is still in progress), or because the query failed.
        // In order to not flash the error dialog at the user for the
        // first case, simply retry the query when the cursor is null.
        // Worst case, we end up doing the same query twice.
        if (mPlaylistCursor != null) {
            init(mPlaylistCursor);
        } else {
            //setTitle(R.string.working_playlists);
            getPlaylistCursor(mAdapter.getQueryHandler(), null);
        }
    }

    return view;
}