本文整理汇总了Java中android.os.Bundle.get方法的典型用法代码示例。如果您正苦于以下问题:Java Bundle.get方法的具体用法?Java Bundle.get怎么用?Java Bundle.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.os.Bundle
的用法示例。
在下文中一共展示了Bundle.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: putBundleToEditor
import android.os.Bundle; //导入方法依赖的package包/类
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);
}
}
}
示例2: put
import android.os.Bundle; //导入方法依赖的package包/类
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;
}
示例3: dumpExtras
import android.os.Bundle; //导入方法依赖的package包/类
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;
}
示例4: addResultsToIntent
import android.os.Bundle; //导入方法依赖的package包/类
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));
}
示例5: getSMSMessages
import android.os.Bundle; //导入方法依赖的package包/类
@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;
}
示例6: PersistableBundle
import android.os.Bundle; //导入方法依赖的package包/类
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);
}
}
}
示例7: encodePostBody
import android.os.Bundle; //导入方法依赖的package包/类
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();
}
示例8: onReceive
import android.os.Bundle; //导入方法依赖的package包/类
@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);
}
}
示例9: onReceive
import android.os.Bundle; //导入方法依赖的package包/类
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]));
}
}
}
}
示例10: onReceive
import android.os.Bundle; //导入方法依赖的package包/类
@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);
}
}
示例11: parseDecodeHints
import android.os.Bundle; //导入方法依赖的package包/类
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;
}
示例12: onActivityResult
import android.os.Bundle; //导入方法依赖的package包/类
/**
* 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));
}
}
示例13: onActivityResult
import android.os.Bundle; //导入方法依赖的package包/类
@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);
}
}
示例14: getSmsMessageBodyFromIntent
import android.os.Bundle; //导入方法依赖的package包/类
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();
}
示例15: onUserAction
import android.os.Bundle; //导入方法依赖的package包/类
/**
* 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?");
}
}