Code example for Intent

Methods: resolveActivityInfotoUri

0
            mParent.startActivityForResult(intent, requestCodeShortcut);
        } 
    } 
 
    private void completeSetCustomApp(Intent data) {
        mListener.shortcutPicked(data.toUri(0), getFriendlyActivityName(data, false), null, true);
    } 
 
    private void completeSetCustomShortcut(Intent data) {
        Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
        /* preserve shortcut name, we want to restore it later */ 
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
                data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME));
        String appUri = intent.toUri(0);
        appUri = appUri.replaceAll("com.android.contacts.action.QUICK_CONTACT",
                "android.intent.action.VIEW"); 
        /* Try to get the icon (if any) */ 
        Bitmap bmp = null;
        Parcelable extra = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
        if (extra != null && extra instanceof Bitmap) {
            bmp = (Bitmap) extra;
        } 
        if (bmp == null) {
            extra = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
            if (extra != null && extra instanceof Intent.ShortcutIconResource) {
                try { 
                    Intent.ShortcutIconResource iconResource = (ShortcutIconResource) extra;
                    final PackageManager packageManager = mParent.getActivity().getPackageManager();
                    Resources resources =
                            packageManager.getResourcesForApplication(iconResource.packageName);
                    final int id = resources.getIdentifier(iconResource.resourceName, null, null);
                    bmp = BitmapFactory.decodeResource(resources, id);
                } catch (Exception e) {
                    Log.w("ROMControl.ShortcutPicker", "Could not load shortcut icon: " + extra);
                } 
            } 
        } 
        mListener.shortcutPicked(appUri, getFriendlyShortcutName(intent), bmp, false);
    } 
 
    private String getFriendlyActivityName(Intent intent, boolean labelOnly) {
        PackageManager pm = mParent.getActivity().getPackageManager();
        ActivityInfo ai = intent.resolveActivityInfo(pm, PackageManager.GET_ACTIVITIES);
        String friendlyName = null;
 
        if (ai != null) {
            friendlyName = ai.loadLabel(pm).toString();
            if (friendlyName == null && !labelOnly) {
                friendlyName = ai.name;
            } 
        } 
 
        return friendlyName != null || labelOnly ? friendlyName : intent.toUri(0);
    } 
 
    private String getFriendlyShortcutName(Intent intent) {
        String activityName = getFriendlyActivityName(intent, true);
        String name = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Contextual code suggestions in your IDE  Get Codota for Java