Example usage for android.content Intent getParcelableExtra

List of usage examples for android.content Intent getParcelableExtra

Introduction

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

Prototype

public <T extends Parcelable> T getParcelableExtra(String name) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:com.nestapi.lib.UserAuthActivity.java

static AccessToken getAccessToken(Intent data) {
    return data == null ? null : (AccessToken) data.getParcelableExtra(ACCESS_TOKEN_KEY);
}

From source file:android.support.customtabs.browseractions.BrowserActionsIntent.java

/**
 * Get the package name of the creator application.
 * @param intent The {@link BrowserActionsIntent}.
 * @return The creator package name./*from w  w  w .jav a 2s .  c om*/
 */
@SuppressWarnings("deprecation")
public static String getCreatorPackageName(Intent intent) {
    PendingIntent pendingIntent = intent.getParcelableExtra(BrowserActionsIntent.EXTRA_APP_ID);
    if (pendingIntent != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            return pendingIntent.getCreatorPackage();
        } else {
            return pendingIntent.getTargetPackage();
        }
    }
    return null;
}

From source file:Main.java

public static String getAppName(Context context, Intent appIntent) {

    if (appIntent.hasExtra(Intent.EXTRA_SHORTCUT_NAME)) {
        return appIntent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
    }//from www  .  j  a  v  a 2 s  .  c om

    if (appIntent.hasExtra(Intent.EXTRA_SHORTCUT_INTENT)) {
        appIntent = appIntent.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    }
    ComponentName componentName = appIntent.getComponent();

    PackageManager pm = context.getPackageManager();

    ApplicationInfo appInfo = null;
    ActivityInfo activityInfo = null;
    try {
        appInfo = pm.getApplicationInfo(componentName.getPackageName(), 0);
    } catch (PackageManager.NameNotFoundException e) {
        appInfo = null;
    }
    try {
        activityInfo = pm.getActivityInfo(componentName, 0);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    if (appInfo == null) {
        return null;
    } else {
        CharSequence appName = pm.getApplicationLabel(appInfo);
        CharSequence activityName = null;

        if (activityInfo != null) {
            activityName = activityInfo.loadLabel(pm);
        }

        if (activityName != null) {
            return activityName.toString();
        }

        if (appName != null) {
            appName.toString();
        }

        return null;
    }
}

From source file:com.android.contacts.util.AccountFilterUtil.java

/**
 * Useful method to handle onActivityResult() for
 * {@link #startAccountFilterActivityForResult(Fragment, int, ContactListFilter)}.
 *
 * This will update filter via a given ContactListFilterController.
 *//*from  w w  w  . j ava  2  s .c o m*/
public static void handleAccountFilterResult(ContactListFilterController filterController, int resultCode,
        Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        final ContactListFilter filter = (ContactListFilter) data
                .getParcelableExtra(AccountFilterActivity.EXTRA_CONTACT_LIST_FILTER);
        if (filter == null) {
            return;
        }
        if (filter.filterType == ContactListFilter.FILTER_TYPE_CUSTOM) {
            filterController.selectCustomFilter();
        } else {
            filterController.setContactListFilter(filter, /* persistent */
                    filter.filterType == ContactListFilter.FILTER_TYPE_ALL_ACCOUNTS);
        }
    }
}

From source file:com.dragedy.playermusic.service.MediaButtonIntentReceiver.java

public static boolean handleIntent(final Context context, final Intent intent) {
    final String intentAction = intent.getAction();
    if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
        final KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
        if (event == null) {
            return false;
        }// w  ww. jav  a 2s .c om

        final int keycode = event.getKeyCode();
        final int action = event.getAction();
        final long eventTime = event.getEventTime();

        String command = null;
        switch (keycode) {
        case KeyEvent.KEYCODE_MEDIA_STOP:
            command = MusicService.ACTION_STOP;
            break;
        case KeyEvent.KEYCODE_HEADSETHOOK:
        case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
            command = MusicService.ACTION_TOGGLE_PAUSE;
            break;
        case KeyEvent.KEYCODE_MEDIA_NEXT:
            command = MusicService.ACTION_SKIP;
            break;
        case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
            command = MusicService.ACTION_REWIND;
            break;
        case KeyEvent.KEYCODE_MEDIA_PAUSE:
            command = MusicService.ACTION_PAUSE;
            break;
        case KeyEvent.KEYCODE_MEDIA_PLAY:
            command = MusicService.ACTION_PLAY;
            break;
        }
        if (command != null) {
            if (action == KeyEvent.ACTION_DOWN) {
                if (event.getRepeatCount() == 0) {
                    // Only consider the first event in a sequence, not the repeat events,
                    // so that we don't trigger in cases where the first event went to
                    // a different app (e.g. when the user ends a phone call by
                    // long pressing the headset button)

                    // The service may or may not be running, but we need to send it
                    // a command.
                    if (keycode == KeyEvent.KEYCODE_HEADSETHOOK) {
                        if (eventTime - mLastClickTime >= DOUBLE_CLICK) {
                            mClickCounter = 0;
                        }

                        mClickCounter++;
                        if (DEBUG)
                            Log.v(TAG, "Got headset click, count = " + mClickCounter);
                        mHandler.removeMessages(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT);

                        Message msg = mHandler.obtainMessage(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT, mClickCounter, 0,
                                context);

                        long delay = mClickCounter < 3 ? DOUBLE_CLICK : 0;
                        if (mClickCounter >= 3) {
                            mClickCounter = 0;
                        }
                        mLastClickTime = eventTime;
                        acquireWakeLockAndSendMessage(context, msg, delay);
                    } else {
                        startService(context, command);
                    }
                    return true;
                }
            }
        }
    }
    return false;
}

From source file:com.ez.gallery.ucrop.UCrop.java

/**
 * Retrieve cropped image Uri from the result Intent
 *
 * @param intent crop result intent//ww  w. j av  a2  s .c o  m
 */
@Nullable
public static Uri getOutput(@NonNull Intent intent) {
    return intent.getParcelableExtra(EXTRA_OUTPUT_URI);
}

From source file:edu.stanford.mobisocial.dungbeetle.model.AppState.java

@Deprecated
public static AppState fromIntent(Intent intent) {
    String arg = intent.getStringExtra(EXTRA_APPLICATION_ARGUMENT);
    String pkg = intent.getStringExtra(EXTRA_APPLICATION_PACKAGE);
    String state = intent.getStringExtra(EXTRA_APPLICATION_STATE);
    String thumbImg = intent.getStringExtra(EXTRA_APPLICATION_IMG);
    String thumbText = intent.getStringExtra(EXTRA_APPLICATION_TEXT);
    Uri feedUri = (Uri) intent.getParcelableExtra(EXTRA_FEED_URI);
    return new AppState(pkg, arg, state, thumbImg, thumbText, feedUri.getLastPathSegment(), null);
}

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

/**
 * @return true is the extra is either null or is of type {@param type}
 *//*w ww  . j a  v  a 2s  . c o  m*/
private static boolean isValidExtraType(Intent intent, String key, Class type) {
    Object extra = intent.getParcelableExtra(key);
    return extra == null || type.isInstance(extra);
}

From source file:com.facebook.notifications.NotificationsManager.java

/**
 * Present a card from the notification this activity
 * was relaunched from, if the notification exists.
 *
 * @param activity The activity to present from.
 * @param intent   Intent that was used to re-launch the activity.
 * @return Whether or not a card was presented.
 *//*from   w w  w  .ja v a2 s . com*/
public static boolean presentCardFromNotification(@NonNull Activity activity, @NonNull Intent intent) {
    Intent notificationIntent = intent.getParcelableExtra(EXTRA_PAYLOAD_INTENT);
    if (notificationIntent == null) {
        return false;
    }

    activity.startActivityForResult(notificationIntent, REQUEST_CODE);
    return true;
}

From source file:androidx.media.session.MediaButtonReceiver.java

/**
 * Extracts any available {@link KeyEvent} from an {@link Intent#ACTION_MEDIA_BUTTON}
 * intent, passing it onto the {@link MediaSessionCompat} using
 * {@link MediaControllerCompat#dispatchMediaButtonEvent(KeyEvent)}, which in turn
 * will trigger callbacks to the {@link MediaSessionCompat.Callback} registered via
 * {@link MediaSessionCompat#setCallback(MediaSessionCompat.Callback)}.
 * @param mediaSessionCompat A {@link MediaSessionCompat} that has a
 *            {@link MediaSessionCompat.Callback} set.
 * @param intent The intent to parse.//from ww  w  . ja va2s  . c  o  m
 * @return The extracted {@link KeyEvent} if found, or null.
 */
public static KeyEvent handleIntent(MediaSessionCompat mediaSessionCompat, Intent intent) {
    if (mediaSessionCompat == null || intent == null || !Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())
            || !intent.hasExtra(Intent.EXTRA_KEY_EVENT)) {
        return null;
    }
    KeyEvent ke = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
    MediaControllerCompat mediaController = mediaSessionCompat.getController();
    mediaController.dispatchMediaButtonEvent(ke);
    return ke;
}