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

The following are Jave code examples for showing how to use keySet() 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: Liteframework   File: NotificationService.java   View Source Code Vote up 7 votes
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
    if (Log.isPrint) {
        Log.i(TAG, sbn.toString());
        Notification notification = sbn.getNotification();
        Log.i(TAG, "tickerText : " + notification.tickerText);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Bundle bundle = notification.extras;
            for (String key : bundle.keySet()) {
                Log.i(TAG, key + ": " + bundle.get(key));
            }
        }
    }
    if (self != null && notificationListener != null) {
        notificationListener.onNotificationPosted(sbn);
    }
}
 
Example 2
Project: devsuite-android   File: MultiFragmentStatePagerAdapter.java   View Source Code Vote up 6 votes
private void restoreFragments(Bundle bundle) {
    Iterable<String> keys = bundle.keySet();
    for (String key : keys) {
        if (key.startsWith("f")) {
            // key sample "f1-2"
            int position = Integer.parseInt(key.substring(1, key.indexOf("-")));
            int viewMode = Integer.parseInt(key.substring(key.indexOf("-") + 1));
            Fragment f = mFragmentManager.getFragment(bundle, key);
            if (f != null) {
                while (mFragments.size() <= position) {
                    mFragments.add(null);
                }
                f.setMenuVisibility(false);
                setFragment(position, viewMode, f);
            } else {
                Log.w(TAG, "Bad fragment at key " + key);
            }
        }
    }
}
 
Example 3
Project: Renrentou   File: JpushReceiver.java   View Source Code Vote up 6 votes
private MyMessage getMessage(Bundle bundle){
    MyMessage message = new MyMessage();
    message.setIsScanned(0);
    for (String key : bundle.keySet()) {
        if (key.equals(JPushInterface.EXTRA_NOTIFICATION_ID)) {
            message.setNotifyId(String.valueOf(bundle.getInt(key)));
        }else if(key.equals(JPushInterface.EXTRA_ALERT)){
            message.setAlert(bundle.getString(key));
        } else if (key.equals(JPushInterface.EXTRA_MSG_ID)) {
            message.setMsgId(bundle.getString(key));
        } else if (key.equals(JPushInterface.EXTRA_ALERT_TYPE)) {
            message.setType(bundle.getString(key));
        }else if (key.equals(JPushInterface.EXTRA_EXTRA)) {
            if (TextUtils.isEmpty(bundle.getString(JPushInterface.EXTRA_EXTRA))) {
                Log.d(TAG, "This message has no Extra data");
                continue;
            }

            try {
                JSONObject json = new JSONObject(bundle.getString(JPushInterface.EXTRA_EXTRA));
                Iterator<String> it =  json.keys();

                while (it.hasNext()) {
                    String myKey = it.next().toString();
                    if(myKey.equals("title")){
                        message.setTitle(json.optString(myKey));
                    }else if(myKey.equals("date")){
                        message.setDate(json.optString(myKey));
                    }

                }
            } catch (JSONException e) {
                Log.e(TAG, "Get message extra JSON error!");
            }

        }
    }
    return message;
}
 
Example 4
Project: toolargetool   File: TooLargeTool.java   View Source Code Vote up 6 votes
/**
 * Measure the sizes of all the values in a typed {@link Bundle} when written to a
 * {@link Parcel}. Returns a map from keys to the sizes, in bytes, of the associated values in
 * the Bundle.
 *
 * @param bundle to measure
 * @return a map from keys to value sizes in bytes
 */
public static Map<String, Integer> valueSizes(@NonNull Bundle bundle) {
    Map<String, Integer> result = new HashMap<>(bundle.size());
    // We measure the size of each value by measuring the total size of the bundle before and
    // after removing that value and calculating the difference. We make a copy of the original
    // bundle so we can put all the original values back at the end. It's not possible to
    // carry out the measurements on the copy because of the way Android parcelables work
    // under the hood where certain objects are actually stored as references.
    Bundle copy = new Bundle(bundle);
    try {
        int bundleSize = sizeAsParcel(bundle);
        // Iterate over copy's keys because we're removing those of the original bundle
        for (String key : copy.keySet()) {
            bundle.remove(key);
            int newBundleSize = sizeAsParcel(bundle);
            int valueSize = bundleSize - newBundleSize;
            result.put(key, valueSize);
            bundleSize = newBundleSize;
        }
        return result;
    } finally {
        // Put everything back into original bundle
        bundle.putAll(copy);
    }
}
 
Example 5
Project: boohee_v5.6   File: Util.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 + a.e +
                    "\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 6
Project: Saiy-PS   File: AssistantIntentService.java   View Source Code Vote up 6 votes
/**
 * For debugging the intent extras
 *
 * @param intent containing potential extras
 */
private void examineIntent(@Nullable final Intent intent) {
    if (DEBUG) {
        MyLog.i(CLS_NAME, "examineIntent");
    }

    if (intent != null) {
        final Bundle bundle = intent.getExtras();
        if (bundle != null) {
            final Set<String> keys = bundle.keySet();
            for (final String key : keys) {
                if (DEBUG) {
                    MyLog.v(CLS_NAME, "examineIntent: " + key + " ~ " + bundle.get(key));
                }
            }
        }
    }
}
 
Example 7
Project: androidBackFlow   File: BackFlow.java   View Source Code Vote up 6 votes
public static void logIntent(String handleObjectSimpleName, Intent data) {
    if (data == null || data.getExtras() == null) {
        return;
    }

    log(BackFlow._TAG, "╔═══════════════════════════════════════════════════════════════════════════════════════");
    log(BackFlow._TAG, "║curr handle object:" + handleObjectSimpleName);

    Bundle bundle = data.getExtras();
    for (String key : bundle.keySet()) {
        String value = String.valueOf(bundle.get(key));
        log(BackFlow._TAG, "║" + key + ":" + value);
    }

    log(BackFlow._TAG, "╚═══════════════════════════════════════════════════════════════════════════════════════");
}
 
Example 8
Project: leoapp-sources   File: MainActivity.java   View Source Code Vote up 5 votes
private void processIntent() {
    if (getIntent().getExtras() != null) {
        Bundle extras = getIntent().getExtras();
        for (String key : extras.keySet()) {
            Utils.logError(key + " = " + extras.get(key).toString());
        }
    }

    if (getIntent().hasExtra("start_intent")) {
        Utils.getController().closeActivities();

        int notificationTarget = getIntent().getIntExtra("start_intent", -1);

        switch (notificationTarget) {
            case NotificationHandler.ID_ESSENSBONS:
                startActivity(new Intent(getApplicationContext(), EssensbonActivity.class));
                break;

            case NotificationHandler.ID_KLAUSURPLAN:
                startActivity(new Intent(getApplicationContext(), KlausurplanActivity.class));
                break;

            case NotificationHandler.ID_MESSENGER:
                startActivity(new Intent(getApplicationContext(), MessengerActivity.class));
                break;

            case NotificationHandler.ID_UMFRAGEN:
                startActivity(new Intent(getApplicationContext(), SurveyActivity.class));
                break;

            case NotificationHandler.ID_SCHWARZES_BRETT:
                startActivity(new Intent(getApplicationContext(), SchwarzesBrettActivity.class));
                break;
        }
    }
}
 
Example 9
Project: Saiy-PS   File: AssistantIntentService.java   View Source Code Vote up 5 votes
/**
 * For debugging the intent extras
 *
 * @param bundle containing potential extras
 */
private void examineBundle(@Nullable final Bundle bundle) {
    if (DEBUG) {
        MyLog.i(CLS_NAME, "examineBundle");
    }

    if (bundle != null) {
        final Set<String> keys = bundle.keySet();
        for (final String key : keys) {
            if (DEBUG) {
                MyLog.v(CLS_NAME, "examineBundle: " + key + " ~ " + bundle.get(key));
            }
        }
    }
}
 
Example 10
Project: xlight_android_native   File: Parcelables.java   View Source Code Vote up 5 votes
public static <T extends Serializable> Map<String, T> readSerializableMap(Parcel parcel) {
    Map<String, T> map = new ArrayMap<>();
    Bundle bundle = parcel.readBundle(Parcelables.class.getClassLoader());
    for (String key : bundle.keySet()) {
        @SuppressWarnings("unchecked")
        T serializable = (T) bundle.getSerializable(key);
        map.put(key, serializable);
    }
    return map;
}
 
Example 11
Project: boohee_v5.6   File: FragmentStatePagerAdapter.java   View Source Code Vote up 5 votes
public void restoreState(Parcelable state, ClassLoader loader) {
    if (state != null) {
        Bundle bundle = (Bundle) state;
        bundle.setClassLoader(loader);
        Parcelable[] fss = bundle.getParcelableArray("states");
        this.mSavedState.clear();
        this.mFragments.clear();
        if (fss != null) {
            for (Parcelable parcelable : fss) {
                this.mSavedState.add((SavedState) parcelable);
            }
        }
        for (String key : bundle.keySet()) {
            if (key.startsWith("f")) {
                int index = Integer.parseInt(key.substring(1));
                Fragment f = this.mFragmentManager.getFragment(bundle, key);
                if (f != null) {
                    while (this.mFragments.size() <= index) {
                        this.mFragments.add(null);
                    }
                    f.setMenuVisibility(false);
                    this.mFragments.set(index, f);
                } else {
                    Log.w(TAG, "Bad fragment at key " + key);
                }
            }
        }
    }
}
 
Example 12
Project: container   File: VAccountManagerService.java   View Source Code Vote up 5 votes
private boolean insertAccountIntoDatabase(int userId, Account account, String password, Bundle extras) {
	if (account == null) {
		return false;
	}
	synchronized (accountsByUserId) {
           VAccount vAccount = new VAccount(userId, account);
           vAccount.password = password;
           // convert the [Bundle] to [Map<String, String>]
           if (extras != null) {
               for (String key : extras.keySet()) {
                   Object value = extras.get(key);
                   if (value instanceof String) {
                       vAccount.userDatas.put(key, (String) value);
                   }
               }
           }
           List<VAccount> accounts = accountsByUserId.get(userId);
           if (accounts == null) {
               accounts = new ArrayList<>();
               accountsByUserId.put(userId, accounts);
           }
           accounts.add(vAccount);
           serializeAllAccounts();
           sendAccountsChangedBroadcast(vAccount.userId);
           return true;
       }
}
 
Example 13
Project: chromium-for-android-56-debug-video   File: IntentHandler.java   View Source Code Vote up 5 votes
/**
 * Gets the referrer, looking in the Intent extra and in the extra headers extra.
 *
 * The referrer extra takes priority over the "extra headers" one.
 *
 * @param intent The Intent containing the extras.
 * @param context The application context.
 * @return The referrer, or null.
 */
public static String getReferrerUrlIncludingExtraHeaders(Intent intent, Context context) {
    String referrerUrl = getReferrerUrl(intent, context);
    if (referrerUrl != null) return referrerUrl;

    Bundle bundleExtraHeaders = IntentUtils.safeGetBundleExtra(intent, Browser.EXTRA_HEADERS);
    if (bundleExtraHeaders == null) return null;
    for (String key : bundleExtraHeaders.keySet()) {
        String value = bundleExtraHeaders.getString(key);
        if ("referer".equals(key.toLowerCase(Locale.US)) && isValidReferrerHeader(value)) {
            return value;
        }
    }
    return null;
}
 
Example 14
Project: MKAPP   File: Util.java   View Source Code Vote up 5 votes
public static void logBundle(Bundle data) {
    if (data != null) {
        Set<String> keys = data.keySet();
        StringBuilder stringBuilder = new StringBuilder();
        for (String key : keys) {
            Object value = data.get(key);
            stringBuilder.append(key)
                    .append("=")
                    .append(value)
                    .append(value == null ? "" : " (" + value.getClass().getSimpleName() + ")")
                    .append("\r\n");
        }
        Log.d(TAG, stringBuilder.toString());
    }
}
 
Example 15
Project: LaunchEnr   File: Utilities.java   View Source Code Vote up 5 votes
/**
 * Returns true if {@param original} contains all entries defined in {@param updates} and
 * have the same value.
 * The comparison uses {@link Object#equals(Object)} to compare the values.
 */
public static boolean containsAll(Bundle original, Bundle updates) {
    for (String key : updates.keySet()) {
        Object value1 = updates.get(key);
        Object value2 = original.get(key);
        if (value1 == null) {
            if (value2 != null) {
                return false;
            }
        } else if (!value1.equals(value2)) {
            return false;
        }
    }
    return true;
}
 
Example 16
Project: chromium-net-for-android   File: Linker.java   View Source Code Vote up 5 votes
protected HashMap<String, LibInfo> createLibInfoMapFromBundle(Bundle bundle) {
    HashMap<String, LibInfo> map = new HashMap<String, LibInfo>();
    for (String library : bundle.keySet()) {
        LibInfo libInfo = bundle.getParcelable(library);
        map.put(library, libInfo);
    }
    return map;
}
 
Example 17
Project: newIPlay   File: PushReceiver.java   View Source Code Vote up 5 votes
private static String printBundle(Bundle bundle) {
    StringBuilder sb = new StringBuilder();
    for (String key : bundle.keySet()) {
        if (key.equals(JPushInterface.EXTRA_NOTIFICATION_ID)) {
            sb.append("\nkey:" + key + ", value:" + bundle.getInt(key));
        } else if (key.equals(JPushInterface.EXTRA_CONNECTION_CHANGE)) {
            sb.append("\nkey:" + key + ", value:" + bundle.getBoolean(key));
        } else if (key.equals(JPushInterface.EXTRA_EXTRA)) {
            if (bundle.getString(JPushInterface.EXTRA_EXTRA).isEmpty()) {
                Log.i(TAG, "This message has no Extra data");
                continue;
            }

            try {
                JSONObject json = new JSONObject(bundle.getString(JPushInterface.EXTRA_EXTRA));
                Iterator<String> it = json.keys();

                while (it.hasNext()) {
                    String myKey = it.next().toString();
                    sb.append("\nkey:" + key + ", value: [" +
                            myKey + " - " + json.optString(myKey) + "]");
                }
            } catch (JSONException e) {
                Log.e(TAG, "Get message extra JSON error!");
            }

        } else {
            sb.append("\nkey:" + key + ", value:" + bundle.getString(key));
        }
    }
    return sb.toString();
}
 
Example 18
Project: Easy-Fragment-Argument   File: ArgumentFactory.java   View Source Code Vote up 5 votes
private static void receiveArguments(Fragment fragment) {
    Bundle bundle = fragment.getArguments();
    for (Field field : fragment.getClass().getDeclaredFields()) {
        for (String key : bundle.keySet()) {
            setFieldValues(fragment, field, bundle, key);
        }
    }
}
 
Example 19
Project: react-native-upload-file   File: BundleJSONConverter.java   View Source Code Vote up 5 votes
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;
}
 
Example 20
Project: Android-App-Linking   File: Printer.java   View Source Code Vote up 4 votes
public Printer appendBundle(@Nullable Bundle bundle) {
    if (bundle == null) {
        return this;
    }
    for (String key : bundle.keySet()) {
        appendKey(key);
        Object value = bundle.get(key);
        if (value == null) {
            newLine().append(EMPTY).newLine(2);
            continue;
        }
        Class<?> clazz = value.getClass();
        appendAsClass(clazz).newLine();
        if (clazz.isArray()) {
            Class<?> type = clazz.getComponentType();
            if (type == long.class) {
                append(Arrays.toString((long[]) value));
            } else if (type == int.class) {
                append(Arrays.toString((int[]) value));
            } else if (type == char.class) {
                append(Arrays.toString((char[]) value));
            } else if (type == boolean.class) {
                append(Arrays.toString((boolean[]) value));
            } else if (type == byte.class) {
                append(Arrays.toString((byte[]) value));
            } else if (type == float.class) {
                append(Arrays.toString((float[]) value));
            } else if (type == short.class) {
                append(Arrays.toString((short[]) value));
            } else if (type == double.class) {
                append(Arrays.toString((double[]) value));
            } else if (type == long.class) {
                append(Arrays.toString((long[]) value));
            } else {
                append(Arrays.toString((Object[]) value));
            }
        } else if (value instanceof Bundle) {
            tab().appendBundle((Bundle) value).popSpan();
            continue;
        } else {
            String string = value.toString();
            append(string.isEmpty() ? ZWSP : string);
        }
        newLine(2);
    }
    return this;
}