Java Code Examples for android.os.Bundle.get()

The following are Jave code examples for showing how to use get() of the android.os.Bundle class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: PlusGram   File: LoginActivity.java   View Source Code Vote up 6 votes
private void putBundleToEditor(Bundle bundle, SharedPreferences.Editor editor, String prefix) {
    Set<String> keys = bundle.keySet();
    for (String key : keys) {
        Object obj = bundle.get(key);
        if (obj instanceof String) {
            if (prefix != null) {
                editor.putString(prefix + "_|_" + key, (String) obj);
            } else {
                editor.putString(key, (String) obj);
            }
        } else if (obj instanceof Integer) {
            if (prefix != null) {
                editor.putInt(prefix + "_|_" + key, (Integer) obj);
            } else {
                editor.putInt(key, (Integer) obj);
            }
        } else if (obj instanceof Bundle) {
            putBundleToEditor((Bundle) obj, editor, key);
        }
    }
}
 
Example 2
Project: letv   File: KVUtils.java   View Source Code Vote up 6 votes
public static Bundle put(Bundle to, Bundle from, String key) {
    if (!(to == null || from == null || TextUtils.empty(key) || !from.containsKey(key))) {
        Object value = from.get(key);
        if (value instanceof Boolean) {
            to.putBoolean(key, ((Boolean) value).booleanValue());
        } else if (value instanceof Byte) {
            to.putByte(key, ((Byte) value).byteValue());
        } else if (value instanceof Character) {
            to.putChar(key, ((Character) value).charValue());
        } else if (value instanceof Short) {
            to.putShort(key, ((Short) value).shortValue());
        } else if (value instanceof Integer) {
            to.putInt(key, ((Integer) value).intValue());
        } else if (value instanceof Long) {
            to.putLong(key, ((Long) value).longValue());
        } else if (value instanceof Float) {
            to.putFloat(key, ((Float) value).floatValue());
        } else if (value instanceof Double) {
            to.putDouble(key, ((Double) value).doubleValue());
        } else if (value instanceof String) {
            to.putString(key, (String) value);
        }
    }
    return to;
}
 
Example 3
Project: PrivacyStreams   File: IMUpdatesProvider.java   View Source Code Vote up 6 votes
private String dumpExtras(Bundle extras) {
    String contactName = "";
    if (extras != null) {
        for (String k : extras.keySet()) {
            Object o = extras.get(k);
            if (o instanceof CharSequence[]) {
                // case for "textLines" and such
                CharSequence n = "";
                CharSequence[] data = (CharSequence[]) o;
                for (CharSequence d : data) {
                    n = d;
                }
                contactName = n.toString();
                int in = contactName.indexOf(": ");
                contactName = contactName.substring(0,in);
            }
        }
    }
    return contactName;
}
 
Example 4
Project: boohee_v5.6   File: RemoteInputCompatJellybean.java   View Source Code Vote up 6 votes
static void addResultsToIntent(RemoteInput[] remoteInputs, Intent intent, Bundle results) {
    Bundle resultsBundle = new Bundle();
    for (RemoteInput remoteInput : remoteInputs) {
        Object result = results.get(remoteInput.getResultKey());
        if (result instanceof CharSequence) {
            resultsBundle.putCharSequence(remoteInput.getResultKey(), (CharSequence) result);
        }
    }
    Intent clipIntent = new Intent();
    clipIntent.putExtra("android.remoteinput.resultsData", resultsBundle);
    intent.setClipData(ClipData.newIntent("android.remoteinput.results", clipIntent));
}
 
Example 5
Project: BlackList   File: SMSBroadcastReceiver.java   View Source Code Vote up 6 votes
@SuppressWarnings("deprecation")
private SmsMessage[] getSMSMessages(Intent intent) {
    SmsMessage[] messages = null;
    Bundle bundle = intent.getExtras();
    if (bundle != null) {
        Object[] pdus = (Object[]) bundle.get("pdus");
        if (pdus != null) {
            messages = new SmsMessage[pdus.length];
            for (int i = 0; i < pdus.length; i++) {
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
                    messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
                } else {
                    String format = bundle.getString("format");
                    messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i], format);
                }
            }
        }
    }
    return messages;
}
 
Example 6
Project: JobSchedulerCompat   File: PersistableBundle.java   View Source Code Vote up 6 votes
public PersistableBundle(Bundle bundle) {
    map = new HashMap<>(bundle.size());
    for (String key : bundle.keySet()) {
        Object value = bundle.get(key);
        if (value == null || value instanceof String || value instanceof Integer || value instanceof Long
                || value instanceof Double || value instanceof Boolean || value instanceof String[]
                || value instanceof int[] || value instanceof long[] || value instanceof double[]
                || value instanceof boolean[]) {
            map.put(key, value);
        } else if (value instanceof Bundle) {
            map.put(key, new PersistableBundle((Bundle) value));
        } else {
            throw new IllegalArgumentException("Unsupported value type key=" + key + " value=" + value);
        }
    }
}
 
Example 7
Project: letv   File: HttpUtils.java   View Source Code Vote up 6 votes
public static String encodePostBody(Bundle bundle, String str) {
    if (bundle == null) {
        return "";
    }
    StringBuilder stringBuilder = new StringBuilder();
    int size = bundle.size();
    int i = -1;
    for (String str2 : bundle.keySet()) {
        int i2 = i + 1;
        Object obj = bundle.get(str2);
        if (obj instanceof String) {
            stringBuilder.append("Content-Disposition: form-data; name=\"" + str2 + "\"" + "\r\n" + "\r\n" + ((String) obj));
            if (i2 < size - 1) {
                stringBuilder.append("\r\n--" + str + "\r\n");
            }
            i = i2;
        } else {
            i = i2;
        }
    }
    return stringBuilder.toString();
}
 
Example 8
Project: XERUNG   File: DetectSms.java   View Source Code Vote up 5 votes
@Override
public void onReceive(Context context, Intent intent) {
    // Retrieves a map of extended data from the intent.
    final Bundle bundle = intent.getExtras();
    try {
        if (bundle != null) {
            final Object[] pdusObj = (Object[]) bundle.get("pdus");
            for (int i = 0; i < pdusObj.length; i++) {
                SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
                String phoneNumber = currentMessage.getDisplayOriginatingAddress();
                String sendername = currentMessage.getOriginatingAddress();
                Log.d(TAG, "sendername is " + sendername);
                String servicecntradd = currentMessage.getServiceCenterAddress();
                Log.d(TAG, "servicecenteraddress is : " + servicecntradd);
                String senderNum = phoneNumber;
                Log.d(TAG, "Displayoriginationg address is : " + sendername);
                String message = currentMessage.getDisplayMessageBody();
                Log.d(TAG, "senderNum: " + senderNum + "; message: " + message);
                if (senderNum.equalsIgnoreCase("IM-MEDICO")||senderNum.equalsIgnoreCase("AD-MEDICO")||senderNum.equalsIgnoreCase("DM-MEDICO")||senderNum.equalsIgnoreCase("AM-MEDICO")) {
                    if (!message.isEmpty()) {
                        Pattern intsOnly = Pattern.compile("\\d{5}");
                        Matcher makeMatch = intsOnly.matcher(message);
                        makeMatch.find();
                        OTPcode = makeMatch.group();
                        Intent intentNew = new Intent();
                        intentNew.setAction("SMS_RECEIVED");
                        intentNew.putExtra("otp_code", OTPcode);
                        context.sendBroadcast(intentNew);
                        System.out.println(OTPcode);
                    }
                } else {
                    //Toast.makeText(context, "didn't identified the number", Toast.LENGTH_LONG).show();
                }
            }// end for loop
        } // bundle is null

    } catch (Exception e) {
        Log.e("SmsReceiver", "Exception smsReceiver" + e);
    }
}
 
Example 9
Project: NoticeDog   File: SMSApp.java   View Source Code Vote up 5 votes
public void onReceive(Context context, Intent intent) {
    if (SMSApp.this.isAppEnabled && intent.getAction().equals(SMSApp.ACTION_RECEIVED_SMS)) {
        Bundle bundle = intent.getExtras();
        if (bundle != null) {
            Object[] pdus = (Object[]) bundle.get("pdus");
            if (pdus != null) {
                SMSApp.this.onSMSReceived(SmsMessage.createFromPdu((byte[]) pdus[0]));
            }
        }
    }
}
 
Example 10
Project: LaunchTime   File: ShortcutReceiver.java   View Source Code Vote up 5 votes
@Override
    public void onReceive(Context context, Intent intent) {
        if (!BuildConfig.DEBUG) Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(context));
        String action = intent.getAction();
        if ("com.android.launcher.action.INSTALL_SHORTCUT".equals(action)) {
            Log.d("ShortcutCatch", "intent received");
            Bundle extras = intent.getExtras();
            if (extras != null) {

                try {
                    Log.d("ShortcutCatch", "Shortcut name: " + intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME));
                    Intent intent2 = (Intent) extras.get(Intent.EXTRA_SHORTCUT_INTENT);
                    Bitmap receivedicon = (Bitmap) extras.get(Intent.EXTRA_SHORTCUT_ICON);
                    if (intent2 != null) {
                        Uri data = intent2.getData();
                        ComponentName cn = intent2.getComponent();


                        String intentaction = intent2.getAction();
                        String shortcutLabel = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
//                        for (String key: intent2.getExtras().keySet()) {
//                            Log.d("ShortcutCatch", " extra2: " + key + " = " + intent2.getExtras().get(key));
//                        }

                        Log.d("ShortcutCatch", "intent2.action=" + intent2.getAction());
                        Log.d("ShortcutCatch", "uri=" + data);
                        if (cn != null) {
                            Log.d("ShortcutCatch", "cn2package=" + cn.getPackageName() + ", cn2classname=" + cn.getClassName());

                            addLink(context, shortcutLabel, data, cn, receivedicon);
                        } else if (intentaction!=null){
                            Log.d("ShortcutCatch", "intentaction=" + intentaction + " uri=" + data);
                            addLink(context, intentaction, shortcutLabel, data, receivedicon);
                        }
                    }
                } catch (Exception e) {
                    Log.e("ShortcutCatch", "Can't make shortcutlink", e);
                }

            }


        } else {
            Log.d("ShortcutCatch", "unknown intent received: " + action);
        }

    }
 
Example 11
Project: weex-3d-map   File: DecodeHintManager.java   View Source Code Vote up 5 votes
static Map<DecodeHintType, Object> parseDecodeHints(Intent intent) {
  Bundle extras = intent.getExtras();
  if (extras == null || extras.isEmpty()) {
    return null;
  }
  Map<DecodeHintType,Object> hints = new EnumMap<>(DecodeHintType.class);

  for (DecodeHintType hintType: DecodeHintType.values()) {

    if (hintType == DecodeHintType.CHARACTER_SET ||
        hintType == DecodeHintType.NEED_RESULT_POINT_CALLBACK ||
        hintType == DecodeHintType.POSSIBLE_FORMATS) {
      continue; // This hint is specified in another way
    }

    String hintName = hintType.name();
    if (extras.containsKey(hintName)) {
      if (hintType.getValueType().equals(Void.class)) {
        // Void hints are just flags: use the constant specified by the DecodeHintType
        hints.put(hintType, Boolean.TRUE);
      } else {
        Object hintData = extras.get(hintName);
        if (hintType.getValueType().isInstance(hintData)) {
          hints.put(hintType, hintData);
        } else {
          Log.w(TAG, "Ignoring hint " + hintType + " because it is not assignable from " + hintData);
        }
      }
    }
  }

  Log.i(TAG, "Hints from the Intent: " + hints);
  return hints;
}
 
Example 12
Project: GoalsAndHabits   File: NewHabitEventActivity.java   View Source Code Vote up 5 votes
/**
 * Handles callback of photo taking activity
 * @param requestCode
 * @param resultCode
 * @param data
 */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
    if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK){
        Bundle extras = data.getExtras();
        imageDisplay = (Bitmap) extras.get("data");
        editPhoto.setImageBitmap(imageDisplay);
        photoEncoded = (ImageController.imageToBase64(imageDisplay));
    }
}
 
Example 13
Project: HabitUp   File: EditHabitEventActivity.java   View Source Code Vote up 5 votes
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
        Bundle extras = data.getExtras();
        imageBitMap = (Bitmap) extras.get("data");

        image.setImageBitmap(imageBitMap);
        image.setVisibility(View.VISIBLE);
    }
}
 
Example 14
Project: PeSanKita-android   File: SmsListener.java   View Source Code Vote up 5 votes
private String getSmsMessageBodyFromIntent(Intent intent) {
  Bundle bundle             = intent.getExtras();
  Object[] pdus             = (Object[])bundle.get("pdus");
  StringBuilder bodyBuilder = new StringBuilder();

  if (pdus == null)
    return null;

  for (Object pdu : pdus)
    bodyBuilder.append(SmsMessage.createFromPdu((byte[])pdu).getDisplayMessageBody());

  return bodyBuilder.toString();
}
 
Example 15
Project: iosched-reader   File: PresenterFragmentImpl.java   View Source Code Vote up 5 votes
/**
 * Called when the user has performed an {@code action}, with data to be passed
 * as a {@link android.os.Bundle} in {@code args}.
 * <p/>
 * Add the constants used to store values in the bundle to the Model implementation class
 * as final static protected strings.
 * <p/>
 * If the {@code action} should trigger a new data query, specify the query ID by storing the
 * associated Integer in the {@code args} using {@link #KEY_RUN_QUERY_ID}. The {@code args} will
 * be passed on to the cursor loader so you can pass in extra arguments for your query.
 */
@Override
public void onUserAction(UserActionEnum action, @Nullable Bundle args) {
    boolean isValid = false;
    if (mValidUserActions != null && mValidUserActions.length > 0 && action != null) {
        for (int i = 0; i < mValidUserActions.length; i++) {
            if (mValidUserActions[i].getId() == action.getId()) {
                isValid = true;
            }
        }
    }
    if (isValid) {
        if (args != null && args.containsKey(KEY_RUN_QUERY_ID)) {
            Object queryId = args.get(KEY_RUN_QUERY_ID);
            if (queryId instanceof Integer) {
                LoaderManager manager = getLoaderManager();
                manager.restartLoader((Integer) queryId, args, this);
            } else {
                // Query id should be an integer!
                LOGE(TAG, "onUserAction called with a bundle containing KEY_RUN_QUERY_ID but"
                        + "the value is not an Integer so it's not a valid query id!");
            }
        }
        boolean success = mModel.requestModelUpdate(action, args);
        if (!success) {
            // User action not understood by model, even though the presenter understands it.
            LOGE(TAG, "Model doesn't implement user action " + action.getId() + ". Have you "
                    + "forgotten to implement this UserActionEnum in your model, or have you "
                    + "called setValidUserActions on your presenter with a UserActionEnum that "
                    + "it shouldn't support?");
        }
    } else {
        // User action not understood.
        LOGE(TAG, "Invalid user action " + action.getId() + ". Have you called "
                + "setValidUserActions on your presenter, with all the UserActionEnum you want "
                + "to support?");
    }
}
 
Example 16
Project: android-library   File: HugoActivity.java   View Source Code Vote up 5 votes
private void setConfigByBundleExtras() {
    Bundle b = getIntent().getExtras();
    if(b!=null) {
        textToTranslate = (String) b.get("HT_StringToTranslate");
        touchoutsideToExit = (boolean) b.get("HT_TouchableToExit");
        typeOfWindow = (int) b.get("HT_WindowType");
        if (touchoutsideToExit) {
            setFinishOnTouchOutside(true);
        }
    }
}
 
Example 17
Project: XERUNG   File: AddNewGroup.java   View Source Code Vote up 5 votes
@Override
  protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
if (requestCode == SELECT_PHOTO && resultCode == RESULT_OK) {
          beginCrop(imageReturnedIntent.getData());
      }else if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
      	 Bundle extras = imageReturnedIntent.getExtras();
           selectedImage = (Bitmap) extras.get("data");
           Uri pp=comman.getImageUri(getApplicationContext(), selectedImage);
           beginCrop(pp);
      } else if (requestCode == Crop.REQUEST_CROP) {
          handleCrop(resultCode, imageReturnedIntent);
      }

  }
 
Example 18
Project: XERUNG   File: AppUpdate.java   View Source Code Vote up 4 votes
private void getBundleData(){

        Bundle bundle = getIntent().getExtras();

        if(bundle != null){

            if(bundle.get("msg") != null){

                if(bundle.get("msg").toString().trim().length() != 0){

                    txtThisVersion.setText(bundle.get("msg").toString().trim());
                    shared.saveSharedData("UpdateMsg", bundle.get("msg").toString().trim());

                }
            }
        }

    }
 
Example 19
Project: ConnectU   File: LauncherActivity.java   View Source Code Vote up 4 votes
@Override
public void onReceive(Context context, Intent intent) {
    Bundle bundle = intent.getExtras();
    String message = (String)bundle.get(Common.INTENT_KEY_ERROR);
    UAUpdate.YearDataLoc num = (UAUpdate.YearDataLoc)bundle.get(Common.INTENT_KEY_LOC);
    if (bundle != null) {
        int resultCode = bundle.getInt(Common.INTENT_KEY_RESULT);
        if (resultCode == RESULT_FIRST_USER) {
            //Completed
            ltext.setText(getString(R.string.completed));
            profile.setImageResource(R.drawable.ic_accept_green);
            completeAccess();
        } else if (resultCode == RESULT_OK) {
            //Continue
            switch(num) {
                case YEARS:
                    ltext.setText(getString(R.string.loading1));
                    break;
                case C_DOSENCIA:
                    ltext.setText(getString(R.string.loading2));
                    break;
                case C_EVALUACION:
                    ltext.setText(getString(R.string.loading3));
                    break;
                case C_EXAMENES:
                    ltext.setText(getString(R.string.loading4));
                    break;
                case C_FESTIVOS:
                    ltext.setText(getString(R.string.loading5));
                    break;
            }
        }else {
            //Failed
            unregisterReceiver(receiver);
            profile.setImageResource(R.drawable.ic_cancel_red);
            ltext.setText(getString(R.string.app_name_error));
            ErrorManager error = new ErrorManager(LauncherActivity.this);
            if (!error.handleError(message)) {
                FirebaseCrash.log("Falied doing normal update in " + num.name());
                FirebaseCrash.log(message);
                FirebaseCrash.report(new Exception("Normal Update Error"));
                Toast.makeText(getBaseContext(), getString(R.string.error_problem_service) + " " + num.name(), Toast.LENGTH_LONG).show();
            }
        }
    }
}
 
Example 20
Project: Lyra   File: BaseCoder.java   View Source Code Vote up 2 votes
/**
 * Read a field's value from the saved state {@link Bundle}.
 *
 * @param state {@link Bundle} used to save the state
 * @param key   key retrieved from {@code fieldDeclaringClass#fieldName}
 * @return value of the field
 */
@Override
public FieldType deserialize(@NonNull Bundle state, @NonNull String key) {
    //noinspection unchecked
    return (FieldType) state.get(key);
}