Code example for Intent

Methods: getParcelableExtragetStringExtraputExtraresolveActivityInfotoUri

0
    private void completeSetCustomApp(Intent data) {
        mListener.shortcutPicked(data.toUri(0), getFriendlyActivityName(data, false), 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");
        mListener.shortcutPicked(appUri, getFriendlyShortcutName(intent), false);
    } 
 
    private String getFriendlyActivityName(Intent intent, boolean labelOnly) {
        ActivityInfo ai = intent.resolveActivityInfo(mPackageManager, PackageManager.GET_ACTIVITIES);
        String friendlyName = null;
        if (ai != null) {
            friendlyName = ai.loadLabel(mPackageManager).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);
 
        if (activityName != null && name != null) {
            return activityName + ": " + name;
        } 
        return name != null ? name : intent.toUri(0);
    } 
 
    public String getFriendlyNameForUri(String uri) {
        if (uri == null) {
            return null;