Example usage for android.os Bundle get

List of usage examples for android.os Bundle get

Introduction

In this page you can find the example usage for android.os Bundle get.

Prototype

@Nullable
public Object get(String key) 

Source Link

Document

Returns the entry with the given key as an object.

Usage

From source file:com.albedinsky.android.support.intent.ImageIntent.java

/**
 * Processes the given result <var>data</var> intent to obtain a user's picked image.
 * <p>//  w  w w  .  jav a2 s  .  c  om
 * <b>Note</b>, that in case of {@link #REQUEST_CODE_CAMERA}, the captured photo's bitmap will be
 * received only in quality of "place holder" image, not as full quality image. For full quality
 * photo pass an instance of Uri to {@link #output(Uri)} and the bitmap of the captured
 * photo will be stored on the specified uri.
 *
 * @param requestCode The request code from {@link Activity#onActivityResult(int, int, Intent)} or
 *                    {@link android.support.v4.app.Fragment#onActivityResult(int, int, Intent)}.
 *                    Can be only one of {@link #REQUEST_CODE_CAMERA} or {@link #REQUEST_CODE_GALLERY}.
 * @param resultCode  The result code from {@link Activity#onActivityResult(int, int, Intent)} or
 *                    {@link android.support.v4.app.Fragment#onActivityResult(int, int, Intent)}.
 *                    If {@link Activity#RESULT_OK}, the passed <var>data</var> will be processed,
 *                    otherwise {@code null} will be returned.
 * @param data        The data from {@link Activity#onActivityResult(int, int, Intent)} or
 *                    {@link android.support.v4.app.Fragment#onActivityResult(int, int, Intent)}.
 * @param context     Current valid context.
 * @param options     Image options to adjust obtained bitmap.
 * @return Instance of Bitmap obtained from the given <var>data</var> Intent.
 */
@Nullable
@SuppressWarnings("deprecation")
public static Bitmap processResultIntent(int requestCode, int resultCode, @Nullable Intent data,
        @NonNull Context context, @Nullable ImageOptions options) {
    if (data == null || resultCode != Activity.RESULT_OK) {
        // User canceled the intent or no data are available.
        return null;
    }
    switch (requestCode) {
    case REQUEST_CODE_GALLERY:
        final Uri imageUri = data.getData();
        Bitmap galleryImage = null;

        if (imageUri != null) {
            InputStream stream = null;
            try {
                stream = context.getContentResolver().openInputStream(imageUri);
            } catch (Exception e) {
                Log.e(TAG, "Unable to open image content at uri(" + imageUri + ").", e);
            } finally {
                if (stream != null) {
                    if (options != null) {
                        // Get the dimensions of the returned bitmap.
                        final BitmapFactory.Options bmOptions = new BitmapFactory.Options();
                        bmOptions.inJustDecodeBounds = true;
                        BitmapFactory.decodeStream(stream, null, bmOptions);
                        final int bmWidth = bmOptions.outWidth;
                        final int bmHeight = bmOptions.outHeight;

                        // Compute how much to scale the bitmap.
                        final int scaleFactor = Math.min(bmWidth / options.width, bmHeight / options.height);

                        // Decode scaled bitmap.
                        bmOptions.inJustDecodeBounds = false;
                        bmOptions.inSampleSize = scaleFactor;
                        bmOptions.inPurgeable = true;
                        galleryImage = BitmapFactory.decodeStream(stream, null, bmOptions);
                    } else {
                        galleryImage = BitmapFactory.decodeStream(stream);
                    }

                    try {
                        stream.close();
                    } catch (IOException e) {
                        Log.e(TAG, "Unable to close image content at uri(" + imageUri + ").", e);
                    }
                }
            }
        }
        return galleryImage;
    case REQUEST_CODE_CAMERA:
        final Bundle extras = data.getExtras();
        try {
            final Bitmap cameraImage = (extras != null) ? (Bitmap) extras.get("data") : null;
            if (cameraImage != null && options != null) {
                return Bitmap.createScaledBitmap(cameraImage, options.width, options.height, false);
            }
            return cameraImage;
        } catch (Exception e) {
            Log.e(TAG, "Failed to retrieve captured image.", e);
        }
    }
    return null;
}

From source file:com.permpings.utils.facebook.sdk.Util.java

public static String encodeUrl(Bundle parameters) {
    if (parameters == null) {
        return "";
    }/*from   ww w .  ja va  2s . co m*/

    StringBuilder sb = new StringBuilder();
    boolean first = true;
    for (String key : parameters.keySet()) {
        Object parameter = parameters.get(key);
        if (!(parameter instanceof String)) {
            continue;
        }

        if (first)
            first = false;
        else
            sb.append("&");
        try {
            sb.append(URLEncoder.encode(key, HTTP.UTF_8) + "="
                    + URLEncoder.encode(parameters.getString(key), HTTP.UTF_8));
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    return sb.toString();
}

From source file:org.linkdroid.PostJob.java

private static final String calculateBundleExtrasHmac(Bundle data, String secretString)
        throws NoSuchAlgorithmException, IOException, InvalidKeyException {
    Mac mac = initHmacSha1(secretString, null);
    SortedSet<String> keys = new TreeSet<String>(data.keySet());
    for (String key : keys) {
        mac.update(key.getBytes(UTF8));//from w w w. ja  va 2s .c  om
        Object value = data.get(key);
        // We only add the value to the hmac digest if it exists; the key is still
        // part of the digest calculation.
        if (value != null) {
            mac.update(value.toString().getBytes(UTF8));
        }
    }
    return hmacDigestToHexString(mac.doFinal());
}

From source file:com.wit.android.support.content.intent.ImageIntent.java

/**
 * Processes the given result <var>data</var> to obtain the requested Bitmap.
 * <p>/*  w ww  .  j a va  2  s .com*/
 * <b>Note</b>, that in case of {@link #REQUEST_CODE_CAMERA}, the obtained Bitmap will be only todo....
 * For full quality image pass an instance of Uri to {@link #output(android.net.Uri)}.
 *
 * @param requestCode The request code from {@link Activity#onActivityResult(int, int, android.content.Intent)} or
 *                    {@link android.support.v4.app.Fragment#onActivityResult(int, int, android.content.Intent)}.
 *                    Can be only one of {@link #REQUEST_CODE_CAMERA} or {@link #REQUEST_CODE_GALLERY}.
 * @param resultCode  The result code from {@link Activity#onActivityResult(int, int, android.content.Intent)} or
 *                    {@link android.support.v4.app.Fragment#onActivityResult(int, int, android.content.Intent)}.
 *                    If {@link Activity#RESULT_OK}, the passed <var>data</var> will be processed,
 *                    otherwise {@code null} will be returned.
 * @param data        The data from {@link Activity#onActivityResult(int, int, android.content.Intent)} or
 *                    {@link android.support.v4.app.Fragment#onActivityResult(int, int, android.content.Intent)}.
 * @param context     Current valid context.
 * @param options     Image options to adjust obtained bitmap.
 * @return Instance of Bitmap obtained from the given <var>data</var> Intent.
 */
@Nullable
public static Bitmap processResultIntent(int requestCode, int resultCode, @Nullable Intent data,
        @NonNull Context context, @Nullable ImageOptions options) {
    if (data != null) {
        switch (resultCode) {
        case Activity.RESULT_OK:
            switch (requestCode) {
            case REQUEST_CODE_GALLERY:
                final Uri imageUri = data.getData();
                Bitmap galleryImage = null;

                if (imageUri != null) {
                    InputStream stream = null;
                    try {
                        stream = context.getContentResolver().openInputStream(imageUri);
                    } catch (Exception e) {
                        Log.e(TAG, "Unable to open image content: " + imageUri, e);
                    } finally {
                        if (stream != null) {
                            if (options != null) {
                                // Get the dimensions of the returned bitmap.
                                final BitmapFactory.Options bmOptions = new BitmapFactory.Options();
                                bmOptions.inJustDecodeBounds = true;
                                BitmapFactory.decodeStream(stream, null, bmOptions);
                                final int bmWidth = bmOptions.outWidth;
                                final int bmHeight = bmOptions.outHeight;

                                // Compute how much to scale the bitmap.
                                final int scaleFactor = Math.min(bmWidth / options.width,
                                        bmHeight / options.height);

                                // Decode scaled bitmap.
                                bmOptions.inJustDecodeBounds = false;
                                bmOptions.inSampleSize = scaleFactor;
                                bmOptions.inPurgeable = true;
                                galleryImage = BitmapFactory.decodeStream(stream, null, bmOptions);
                            } else {
                                galleryImage = BitmapFactory.decodeStream(stream);
                            }

                            try {
                                stream.close();
                            } catch (IOException e) {
                                Log.e(TAG, "Unable to close image content: " + imageUri, e);
                            }
                        }
                    }
                }
                return galleryImage;
            case REQUEST_CODE_CAMERA:
                final Bundle extras = data.getExtras();
                try {
                    final Bitmap cameraImage = (extras != null) ? (Bitmap) extras.get("data") : null;
                    if (cameraImage != null && options != null) {
                        return Bitmap.createScaledBitmap(cameraImage, options.width, options.height, false);
                    }
                    return cameraImage;
                } catch (Exception e) {
                    Log.e(TAG, "Failed to retrieve captured image.", e);
                }
            }
            break;
        case Activity.RESULT_CANCELED:
            // User canceled get image action.
            break;
        }
    }
    return null;
}

From source file:count.ly.messaging.TitaniumCountlyAndroidMessagingModule.java

private static HashMap<String, String> bundleToHashMap(Bundle bundle) {
    HashMap<String, String> hash = new HashMap<String, String>();
    Set<String> keys = bundle.keySet();
    for (String key : keys) {
        hash.put(key, bundle.get(key).toString());
    }/*from w  w w  .j a v a  2  s.c o m*/
    return hash;
}

From source file:com.microsoft.rightsmanagement.ui.ConsentActivity.java

/**
 * Processes the result of ConsentActivity started via startActivityForResult from the parent activity, and invokes
 * the callback supplied to show(). This method must be called from parent Activity's onActivityResult.
 * /*from www  .  jav  a2 s  . c  o  m*/
 * @param resultCode the result code parameter as supplied to parent Activity's onActivityResult
 * @param data the data parameter as supplied to parent Activity's onActivityResult
 */
public static void onActivityResult(int resultCode, Intent data) {
    Logger.ms(TAG, "onActivityResult");
    int requestCallbackId = 0;
    if (data == null) {
        Logger.i(TAG, "System closed the activity", "");
        return;
    }
    try {
        final Bundle extras = data.getExtras();
        requestCallbackId = extras.getInt(REQUEST_CALLBACK_ID);
        final CompletionCallback<Collection<Consent>> callback = sCallbackManager
                .getWaitingRequest(requestCallbackId);
        switch (resultCode) {
        case RESULT_OK:
            Logger.i(TAG, "resultCode=RESULT_OK", "");
            ConsentModel consentModel = (ConsentModel) extras.get(RESULT_CONSENT_MODEL);
            Collection<Consent> consents = sCallbackManager.getState(requestCallbackId);
            for (Consent consent : consents) {
                if (consent.getConsentType() == ConsentType.SERVICE_URL_CONSENT
                        || consent.getConsentType() == ConsentType.DOCUMENT_TRACKING_CONSENT) {
                    ConsentResult consentResult = new ConsentResult(consentModel.isAccepted(),
                            consentModel.isShowAgain(), null);
                    consent.setConsentResult(consentResult);
                }
            }
            callback.onSuccess(consents);
            break;
        case RESULT_CANCELED:
            Logger.i(TAG, "resultCode=RESULT_CANCELED", "");
            callback.onCancel();
            break;
        }
    } finally {
        if (requestCallbackId != 0) {
            sCallbackManager.removeWaitingRequest(requestCallbackId);
        }
        Logger.me(TAG, "onActivityResult");
    }
}

From source file:Main.java

/**
 * Compares two {@link android.os.Bundle Bundles} to check for equality.
 *
 * @param a the first {@link android.os.Bundle Bundle}
 * @param b the second {@link android.os.Bundle Bundle}
 * @return {@code true} if the two {@link android.os.Bundle Bundles} have identical contents, or are both null
 *//*  w  w w. j a  v  a2s.co m*/
public static boolean areEqual(@Nullable Bundle a, @Nullable Bundle b) {
    // equal if both null
    if (a == null && b == null)
        return true;

    // unequal if one is null
    if (a == null || b == null)
        return false;

    // check size
    if (a.size() != b.size())
        return false;

    // get key sets
    Set<String> bundleAKeys = a.keySet();
    Object valueA;
    Object valueB;

    // loop keys
    for (String key : bundleAKeys) {
        // check key exists in second bundle
        if (!b.containsKey(key))
            return false;

        // get values
        valueA = a.get(key);
        valueB = b.get(key);

        // check null valued entries
        if (valueA == null && valueB == null)
            continue;
        if (valueA == null || valueB == null)
            return false;

        // compare iteratively if they are both bundles
        if (valueA instanceof Bundle && valueB instanceof Bundle) {
            if (!areEqual((Bundle) valueA, (Bundle) valueB))
                return false;
            continue;
        }

        // check for different values
        if (!valueA.equals(valueB))
            return false;
    }

    // passed!
    return true;
}

From source file:com.hybris.mobile.data.WebServiceDataProvider.java

public static String encodePostBody(Bundle parameters) {
    if (parameters == null) {
        return "";
    }//from   ww w . j  a v a  2 s  . com

    StringBuilder sb = new StringBuilder();

    for (Iterator<String> i = parameters.keySet().iterator(); i.hasNext();) {
        String key = i.next();
        Object parameter = parameters.get(key);
        if (!(parameter instanceof String)) {
            continue;
        }

        try {
            sb.append(URLEncoder.encode(key, "UTF-8"));
            sb.append("=");
            sb.append(URLEncoder.encode((String) parameter, "UTF-8"));
        } catch (UnsupportedEncodingException e) {
            // TODO report parse error
            LoggingUtils.e(LOG_TAG, "Error encoding \"" + key + "\" or \"" + parameter + "\" to UTF-8 ."
                    + e.getLocalizedMessage(), null);
        }

        if (i.hasNext()) {
            sb.append("&");
        }
    }
    return sb.toString();
}

From source file:me.myatminsoe.myansms.SmsReceiver.java

static void handleOnReceive(final BroadcastReceiver receiver, final Context context, final Intent intent) {
    final String action = intent.getAction();
    final PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    final PowerManager.WakeLock wakelock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
    wakelock.acquire();//from  w  ww .jav a2 s . co m

    try {

        Thread.sleep(SLEEP);
    } catch (InterruptedException e) {

        e.printStackTrace();
    }
    String t = null;
    if (SenderActivity.MESSAGE_SENT_ACTION.equals(action)) {
        handleSent(context, intent, receiver.getResultCode());
    } else {
        boolean silent = false;

        if (ACTION_SMS_OLD.equals(action) || ACTION_SMS_NEW.equals(action)) {
            Bundle b = intent.getExtras();
            assert b != null;
            Object[] messages = (Object[]) b.get("pdus");
            SmsMessage[] smsMessage = new SmsMessage[messages.length];
            int l = messages.length;
            for (int i = 0; i < l; i++) {
                smsMessage[i] = SmsMessage.createFromPdu((byte[]) messages[i]);
            }
            t = null;
            if (l > 0) {
                // concatenate multipart SMS body
                StringBuilder sbt = new StringBuilder();
                for (int i = 0; i < l; i++) {
                    sbt.append(smsMessage[i].getMessageBody());
                }
                t = sbt.toString();

                // ! Check in blacklist db - filter spam
                String s = smsMessage[0].getDisplayOriginatingAddress();

                // this code is used to strip a forwarding agent and display the orginated number as sender
                final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
                if (prefs.getBoolean(PreferencesActivity.PREFS_FORWARD_SMS_CLEAN, false) && t.contains(":")) {
                    Pattern smsPattern = Pattern.compile("([0-9a-zA-Z+]+):");
                    Matcher m = smsPattern.matcher(t);
                    if (m.find()) {
                        s = m.group(1);
                        // now strip the sender from the message
                        Pattern textPattern = Pattern.compile("^[0-9a-zA-Z+]+: (.*)");
                        Matcher m2 = textPattern.matcher(t);
                        if (t.contains(":") && m2.find()) {
                            t = m2.group(1);
                            Log.d(TAG, "stripped the message");
                        }
                    }
                }

                final SpamDB db = new SpamDB(context);
                db.open();
                if (db.isInDB(smsMessage[0].getOriginatingAddress())) {

                    silent = true;
                }
                db.close();

                if (action.equals(ACTION_SMS_NEW)) {
                    // API19+: save message to the database
                    ContentValues values = new ContentValues();
                    values.put("address", s);
                    values.put("body", t);
                    context.getContentResolver().insert(Uri.parse("content://sms/inbox"), values);
                }
            }
        } else if (ACTION_MMS_OLD.equals(action) || ACTION_MMS_MEW.equals(action)) {
            t = MMS_BODY;
            // TODO API19+ MMS code
        }

        if (!silent) {

            int count = MAX_SPINS;
            do {

                try {

                    Thread.sleep(SLEEP);
                } catch (InterruptedException e) {

                    e.printStackTrace();
                }
                --count;
            } while (updateNewMessageNotification(context, t) <= 0 && count > 0);
            if (count == 0) { // use messages as they are available
                updateNewMessageNotification(context, null);
            }
        }
    }
    wakelock.release();
    Log.i(TAG, "wakelock released");
}

From source file:com.facebook.InsightsLogger.java

private static String buildJSONForEvent(String eventName, double valueToSum, Bundle parameters) {
    String result;/*from   w  ww .jav a 2  s.  co m*/
    try {

        // Build custom event payload
        JSONObject eventObject = new JSONObject();
        eventObject.put("_eventName", eventName);
        if (valueToSum != 1.0) {
            eventObject.put("_valueToSum", valueToSum);
        }

        if (parameters != null) {

            Set<String> keys = parameters.keySet();
            for (String key : keys) {
                Object value = parameters.get(key);

                if (!(value instanceof String) && !(value instanceof Number)) {

                    notifyDeveloperError(
                            String.format("Parameter '%s' must be a string or a numeric type.", key));
                }

                eventObject.put(key, value);
            }
        }

        JSONArray eventArray = new JSONArray();
        eventArray.put(eventObject);

        result = eventArray.toString();

    } catch (JSONException exception) {

        notifyDeveloperError(exception.toString());
        result = null;

    }

    return result;
}