下面列出了android.os.Bundle#get ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@TargetApi(VERSION_CODES.LOLLIPOP_MR1)
public static PersistableBundle bundleToPersistableBundle(Bundle bundle) {
Set<String> keySet = bundle.keySet();
PersistableBundle persistableBundle = new PersistableBundle();
for (String key : keySet) {
Object value = bundle.get(key);
if (value instanceof Boolean) {
persistableBundle.putBoolean(key, (boolean) value);
} else if (value instanceof Integer) {
persistableBundle.putInt(key, (int) value);
} else if (value instanceof String) {
persistableBundle.putString(key, (String) value);
} else if (value instanceof String[]) {
persistableBundle.putStringArray(key, (String[]) value);
} else if (value instanceof Bundle) {
PersistableBundle innerBundle = bundleToPersistableBundle((Bundle) value);
persistableBundle.putPersistableBundle(key, innerBundle);
}
}
return persistableBundle;
}
private static Date getBundleLongAsDate(Bundle bundle, String key, Date dateBase) {
if (bundle == null) {
return null;
}
long secondsFromBase = Long.MIN_VALUE;
Object secondsObject = bundle.get(key);
if (secondsObject instanceof Long) {
secondsFromBase = (Long) secondsObject;
} else if (secondsObject instanceof String) {
try {
secondsFromBase = Long.parseLong((String) secondsObject);
} catch (NumberFormatException e) {
return null;
}
} else {
return null;
}
if (secondsFromBase == 0) {
return new Date(Long.MAX_VALUE);
} else {
return new Date(dateBase.getTime() + (secondsFromBase * 1000L));
}
}
private static String bundle2String(Bundle bundle) {
Iterator<String> iterator = bundle.keySet().iterator();
if (!iterator.hasNext()) {
return "Bundle {}";
}
StringBuilder sb = new StringBuilder(128);
sb.append("Bundle { ");
for (; ; ) {
String key = iterator.next();
Object value = bundle.get(key);
sb.append(key).append('=');
if (value != null && value instanceof Bundle) {
sb.append(value == bundle ? "(this Bundle)" : bundle2String((Bundle) value));
} else {
sb.append(formatObject(value));
}
if (!iterator.hasNext()) return sb.append(" }").toString();
sb.append(',').append(' ');
}
}
public static String formatDeviceInfo(MidiDeviceInfo info) {
StringBuilder sb = new StringBuilder();
if (info != null) {
Bundle properties = info.getProperties();
for (String key : properties.keySet()) {
Object value = properties.get(key);
sb.append(key).append(" = ").append(value).append('\n');
}
for (PortInfo port : info.getPorts()) {
sb.append((port.getType() == PortInfo.TYPE_INPUT) ? "input"
: "output");
sb.append("[").append(port.getPortNumber()).append("] = \"").append(port.getName()
+ "\"\n");
}
}
return sb.toString();
}
private static Date getBundleLongAsDate(Bundle bundle, String key, Date dateBase) {
if (bundle == null) {
return null;
}
long secondsFromBase = Long.MIN_VALUE;
Object secondsObject = bundle.get(key);
if (secondsObject instanceof Long) {
secondsFromBase = (Long) secondsObject;
} else if (secondsObject instanceof String) {
try {
secondsFromBase = Long.parseLong((String) secondsObject);
} catch (NumberFormatException e) {
return null;
}
} else {
return null;
}
if (secondsFromBase == 0) {
return new Date(Long.MAX_VALUE);
} else {
return new Date(dateBase.getTime() + (secondsFromBase * 1000L));
}
}
/**
* 获取manifest中配置的metaData信息
* <meta-data
* android:name="key"
* android:value="value" />
*
* @param ctx
* @param key
* @return
*/
public static String getMetaData(Context ctx, String key) {
String packageName = ctx.getPackageName();
PackageManager packageManager = ctx.getPackageManager();
Bundle bd;
String value = "";
try {
ApplicationInfo info = packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
bd = info.metaData;//获取metaData标签内容
if (bd != null) {
Object keyO = bd.get(key);
if (keyO != null) {
value = keyO.toString();//这里获取的就是value值
}
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return value;
}
@SuppressLint("SetTextI18n")
private void initData() {
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
videoBean = (VideoBean.ItemListBean.DataBeanX) bundle.get("data");
txtVideoTitle.setText(videoBean.getContent().getData().getTitle());
txtVideoSubtitle.setText(videoBean.getHeader().getDescription());
txtVideoContent.setText(videoBean.getContent().getData().getDescription());
txtVideoShare.setText(videoBean.getContent().getData().getConsumption().getShareCount() + "");
txtVideoReply.setText(videoBean.getContent().getData().getConsumption().getReplyCount() + "");
ImageLoader.loadAllNoPlaceHolder(mContext, videoBean.getContent().getData().getAuthor().getIcon(),imgVideoAuthor);
txtVideoAuthorName.setText(videoBean.getContent().getData().getAuthor().getName());
txtVideoAuthorDescription.setText(videoBean.getContent().getData().getAuthor().getDescription());
tagAdapter = new EyepetizerTagAdapter();
tagAdapter.setNewData(videoBean.getContent().getData().getTags().size() > 3
? videoBean.getContent().getData().getTags().subList(0, 3) : videoBean.getContent().getData().getTags());
recyclerviewTag.setLayoutManager(new GridLayoutManager(mContext, 3));
recyclerviewTag.setAdapter(tagAdapter);
daoManager = EncyApplication.getAppComponent().getGreenDaoManager();
setLikeState(daoManager.queryByGuid(videoBean.getHeader().getId() + ""));
}
public static String bundle2string(Bundle bundle) {
if (null == bundle) return "[Bundle null]";
String string = "[Bundle: ";
for (String key : bundle.keySet()) {
string += key + "=" + bundle.get(key) + " ";
}
string += "]";
return string;
}
@Override
public void onReceive(Context context, Intent intent) {
if (intent == null) {
return;
}
try {
String message = "";
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
String hash = preferences.getString("sms_hash", null);
if (SmsRetriever.SMS_RETRIEVED_ACTION.equals(intent.getAction())) {
if (!AndroidUtilities.isWaitingForSms()) {
return;
}
Bundle bundle = intent.getExtras();
message = (String) bundle.get(SmsRetriever.EXTRA_SMS_MESSAGE);
}
if (TextUtils.isEmpty(message)) {
return;
}
Pattern pattern = Pattern.compile("[0-9\\-]+");
final Matcher matcher = pattern.matcher(message);
if (matcher.find()) {
String code = matcher.group(0).replace("-", "");
if (code.length() >= 3) {
if (preferences != null && hash != null) {
preferences.edit().putString("sms_hash_code", hash + "|" + code).commit();
}
AndroidUtilities.runOnUIThread(() -> NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.didReceiveSmsCode, code));
}
}
} catch (Throwable e) {
FileLog.e(e);
}
}
private static IBinder getBinerAPI10(Bundle data, String key) {
Object o = data.get(key);
if (o == null) {
return null;
}
try {
return (IBinder) o;
} catch (ClassCastException e) {
typeWarning(key, o, "IBinder", e);
return null;
}
}
@Override
public void onReceive(Context context, Intent intent) {
if (!Telephony.Sms.Intents.DATA_SMS_RECEIVED_ACTION.equals(intent.getAction())) {
Log.d(TAG, "Received intent, not DATA_SMS_RECEIVED_ACTION, but " + intent.getAction());
return;
}
SharedPreferences preferences = context.getSharedPreferences(PREF_DATA_SMS_STORE, Context.MODE_PRIVATE);
if (!context.getSharedPreferences("MainActivity", Context.MODE_PRIVATE).getBoolean(MainActivity.PREF_RECEIVE_DATA_SMS, false)) {
return;
}
Bundle bundle = intent.getExtras();
if (bundle == null) {
return;
}
Object[] PDUs = (Object[]) bundle.get("pdus");
Log.d(TAG, "Received " + (PDUs != null ? PDUs.length : 0) + " messages");
int counter = 0;
for (Object pdu : PDUs != null ? PDUs : new Object[0]) {
StringBuilder sb = new StringBuilder();
for (byte b : (byte[]) pdu) {
sb.append(String.format("%02x", b));
}
Log.d(TAG, "HEX[" + (counter + 1) + "]: " + sb.toString());
String storeString = preferences.getString(PREF_DATA_SMS_STORE, "");
storeString += sb.toString() + ",";
preferences.edit().putString(PREF_DATA_SMS_STORE, storeString).apply();
Notification(context, sb.toString());
}
}
private static List<String> getAllBundleValues(Bundle bundle, String[] keys) {
List<String> values = new ArrayList<>(keys.length);
for (String key : keys) {
Object value = bundle.get(key);
values.add(value == null ? null : value.toString());
}
return values;
}
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);
}
}
}
public static JSONObject convertToJSON(Bundle bundle) throws JSONException {
JSONObject json = new JSONObject();
for(String key : bundle.keySet()) {
Object value = bundle.get(key);
if (value == null) {
// Null is not supported.
continue;
}
// Special case List<String> as getClass would not work, since List is an interface
if (value instanceof List<?>) {
JSONArray jsonArray = new JSONArray();
@SuppressWarnings("unchecked")
List<String> listValue = (List<String>)value;
for (String stringValue : listValue) {
jsonArray.put(stringValue);
}
json.put(key, jsonArray);
continue;
}
// Special case Bundle as it's one way, on the return it will be JSONObject
if (value instanceof Bundle) {
json.put(key, convertToJSON((Bundle)value));
continue;
}
Setter setter = SETTERS.get(value.getClass());
if (setter == null) {
throw new IllegalArgumentException("Unsupported type: " + value.getClass());
}
setter.setOnJSON(json, key, value);
}
return json;
}
public static Uri buildUri(String authority, String path, Bundle parameters) {
Uri.Builder builder = new Uri.Builder();
builder.scheme(URL_SCHEME);
builder.authority(authority);
builder.path(path);
if (parameters != null) {
for (String key : parameters.keySet()) {
Object parameter = parameters.get(key);
if (parameter instanceof String) {
builder.appendQueryParameter(key, (String) parameter);
}
}
}
return builder.build();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try{
System.getProperties().setProperty("java.library.path", System.getProperty("java.library.path")+":/data/data/jackpal.androidterm/lib");
String apkfile = getPackageManager().getApplicationInfo("jackpal.androidterm", 0).sourceDir;
classloader = new dalvik.system.PathClassLoader(apkfile, ClassLoader.getSystemClassLoader());
Bundle b = getIntent().getExtras();
//create a new terminal session
session = Class.forName("jackpal.androidterm.emulatorview.TermSession", true, classloader).getConstructor().newInstance(new Object[]{});
SharedPreferences settings = getSharedPreferences("julianwi.javainstaller_preferences", 1);
String[] arguments;
//android terminal emulator version 1.0.66 and later wants the first argument twice
if(b != null && (Boolean)b.get("install")==true){
if(settings.getString("rootmode", "off").equals("on")){
arguments = new String[]{"/system/bin/su", "/system/bin/su", "-c", "sh /data/data/julianwi.javainstaller/install.sh"};
}
else{
arguments = new String[]{"/system/bin/sh", "/system/bin/sh", "/data/data/julianwi.javainstaller/install.sh"};
}
}
else{
String javapath = getSharedPreferences("settings", 1).getString("path3", "");
if(settings.getString("rootmode2", "off").equals("on")){
arguments = new String[]{"/system/bin/su", "/system/bin/su", "-c", "/data/data/julianwi.javainstaller/java -jar "+getIntent().getDataString()};
}
else{
arguments = new String[]{"/data/data/julianwi.javainstaller/java", "/data/data/julianwi.javainstaller/java", "-jar", getIntent().getDataString()};
}
}
//create a pty
if(termexec == null){
termexec = Class.forName("jackpal.androidterm.TermExec", true, classloader);
}
pseudoterm = ParcelFileDescriptor.open(new File("/dev/ptmx"), ParcelFileDescriptor.MODE_READ_WRITE);
exec = termexec.getConstructor(new Class[]{String[].class}).newInstance(new Object[]{arguments});
handler = new Handler();
new Thread(this).start();
//connect the pty's I/O streams to the TermSession.
session.getClass().getMethod("setTermOut", OutputStream.class).invoke(session, new Object[]{new ParcelFileDescriptor.AutoCloseOutputStream(pseudoterm)});
session.getClass().getMethod("setTermIn", InputStream.class).invoke(session, new Object[]{new ParcelFileDescriptor.AutoCloseInputStream(pseudoterm)});
//create the EmulatorView
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
emulatorview = (View) Class.forName("jackpal.androidterm.emulatorview.EmulatorView", true, classloader).getConstructor(Context.class, session.getClass(), DisplayMetrics.class).newInstance(new Object[]{this, session, metrics});
setContentView(emulatorview);
}catch(Exception e){
e.printStackTrace();
new Error("error", e.toString(), this);
}
}
public AppEvent(
Context context,
String eventName,
Double valueToSum,
Bundle parameters,
boolean isImplicitlyLogged
) {
validateIdentifier(eventName);
this.name = eventName;
isImplicit = isImplicitlyLogged;
jsonObject = new JSONObject();
try {
jsonObject.put("_eventName", eventName);
jsonObject.put("_logTime", System.currentTimeMillis() / 1000);
jsonObject.put("_ui", Utility.getActivityName(context));
if (valueToSum != null) {
jsonObject.put("_valueToSum", valueToSum.doubleValue());
}
if (isImplicit) {
jsonObject.put("_implicitlyLogged", "1");
}
String appVersion = Settings.getAppVersion();
if (appVersion != null) {
jsonObject.put("_appVersion", appVersion);
}
if (parameters != null) {
for (String key : parameters.keySet()) {
validateIdentifier(key);
Object value = parameters.get(key);
if (!(value instanceof String) && !(value instanceof Number)) {
throw new FacebookException(
String.format(
"Parameter value '%s' for key '%s' should be a string or a numeric type.",
value,
key)
);
}
jsonObject.put(key, value.toString());
}
}
if (!isImplicit) {
Logger.log(LoggingBehavior.APP_EVENTS, "AppEvents",
"Created app event '%s'", jsonObject.toString());
}
} catch (JSONException jsonException) {
// If any of the above failed, just consider this an illegal event.
Logger.log(LoggingBehavior.APP_EVENTS, "AppEvents",
"JSON encoding for app event failed: '%s'", jsonException.toString());
jsonObject = null;
}
}
private static String buildJSONForEvent(String eventName, double valueToSum, Bundle parameters) {
String result;
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;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneralHandler generalHandler = new GeneralHandler(this);
generalHandler.loadTheme();
setContentView(R.layout.activity_wifi_generator);
tfSSID = (EditText) findViewById(R.id.tfSSID);
tfPassword = (EditText) findViewById(R.id.tfPassword);
cbHidden = (CheckBox) findViewById(R.id.cbHidden);
btnGenerate = (Button) findViewById(R.id.btnGenerateWifi);
btnGenerate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ssid = tfSSID.getText().toString().trim();
password = tfPassword.getText().toString().trim();
if(ssid.equals("") || (encrypt.equals("WEP") && password.equals("")) || (encrypt.equals("WPA") && password.equals(""))){
Toast.makeText(getApplicationContext(), getResources().getText(R.string.error_geo_first), Toast.LENGTH_SHORT).show();
} else {
multiFormatWriter = new MultiFormatWriter();
try{
if(hidden.equals("true") && encrypt.equals("nopass")) {
result = "WIFI:S:" + ssid + ";T:" + encrypt + ";P:;H:true;";
} else if (hidden.equals("false") && encrypt.equals("nopass")){
result = "WIFI:S:" + ssid + ";T:" + encrypt + ";P:;;";
} else if (hidden.matches("false")){
result = "WIFI:S:" + ssid + ";T:" + encrypt + ";P:" + password + ";;";
} else {
result = "WIFI:S:" + ssid + ";T:" + encrypt + ";P:" + password + ";H:true;";
}
openResultActivity();
} catch (Exception e){
Toast.makeText(activity.getApplicationContext(), getResources().getText(R.string.error_generate), Toast.LENGTH_LONG).show();
}
}
}
});
//Setup the Spinner Menu for the different formats
Spinner formatSpinner = (Spinner) findViewById(R.id.spinner);
Spinner encrypSpinner = (Spinner) findViewById(R.id.spinnerWifi);
formatSpinner.setOnItemSelectedListener(this);
encrypSpinner.setOnItemSelectedListener(this);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.text_formats_array, R.layout.spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
formatSpinner.setAdapter(adapter);
adapter = ArrayAdapter.createFromResource(this, R.array.text_formats_encryption, R.layout.spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
encrypSpinner.setAdapter(adapter);
//If the device were rotated then restore information
if(savedInstanceState != null){
ssid = (String) savedInstanceState.get(STATE_SSID);
tfSSID.setText(ssid);
password = (String) savedInstanceState.get(STATE_PASSWORD);
tfPassword.setText(password);
encrypt = (String) savedInstanceState.get(STATE_ENCRYPT);
if(encrypt.equals("nopass")){
tfPassword.setVisibility(View.GONE);
}
hidden = (String) savedInstanceState.get(STATE_HIDDEN);
if(hidden.equals("false")) {
cbHidden.setChecked(false);
}
}
}
private void processIncomingBundle(Bundle bundle) {
final PowerManager.WakeLock wl = JoH.getWakeLock("reminder-bundler", 10000);
if (bundle != null) {
if ((bundle != null) && (d)) {
for (String key : bundle.keySet()) {
Object value = bundle.get(key);
if (value != null) {
Log.d(TAG, String.format("Bundle: %s %s (%s)", key,
value.toString(), value.getClass().getName()));
}
}
}
if (bundle.getString("snooze") != null) {
long id = bundle.getLong("snooze_id");
Log.d(TAG, "Reminder id for snooze: " + id);
final Reminder reminder = Reminder.byid(id);
if (reminder != null) {
final long snooze_time = reminder.last_snoozed_for > 0 ? reminder.last_snoozed_for : default_snooze;
snoozeReminder(reminder, snooze_time);
JoH.static_toast_long(xdrip.getAppContext().getString(R.string.snoozed_reminder_for) + " " + JoH.niceTimeScalar(snooze_time));
reloadList();
hideSnoozeFloater();
hideKeyboard(recyclerView);
}
} else {
Log.d(TAG, "Processing non null default bundle");
reloadList();
hideSnoozeFloater();
hideKeyboard(recyclerView);
JoH.runOnUiThread(new Runnable() {
@Override
public void run() {
wakeUpScreen(false);
}
});
if (bundle.getString(REMINDER_WAKEUP) != null) {
try {
recyclerView.smoothScrollToPosition(getPositionFromReminderId(Integer.parseInt(bundle.getString(REMINDER_WAKEUP))));
} catch (IllegalArgumentException e) {
Log.e(TAG, "Couldn't scroll to position");
}
JoH.runOnUiThreadDelayed(new Runnable() {
@Override
public void run() {
Log.d(TAG, "Checking for sensor: " + proximity);
if (!proximity) {
wakeUpScreen(true);
}
}
}, 2000);
}
}
}
// intentionally don't release wakelock for proximity detection etc
}