List of usage examples for android.os Bundle get
@Nullable
public Object get(String key)
From source file:com.polyvi.xface.extension.messaging.XMessagingExt.java
private void genMsgReceiveBroadcastReceiver() { if (null == mMsgReceiveBroadcaseReceiver) { mMsgReceiveBroadcaseReceiver = new BroadcastReceiver() { @Override// w ww .j ava2s .c om public void onReceive(Context context, Intent intent) { if (INTENT_ACTION.equals(intent.getAction())) { Bundle bundle = intent.getExtras(); if (null != bundle) { // pdus?? Object[] pdus = (Object[]) bundle.get("pdus"); // SmsMessage[] msgs = new SmsMessage[pdus.length]; for (int i = 0; i < pdus.length; i++) { // ???pdu?,? msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]); } JSONArray receivedMsgs = buildSmsList(msgs); XEvent evt = XEvent.createEvent(XEventType.MSG_RECEIVED, receivedMsgs.toString()); ((XFaceMainActivity) mContext).getEventCenter().sendEventAsync(evt); } } } }; } }
From source file:io.ionic.links.IonicDeeplink.java
private JSONObject _bundleToJson(Bundle bundle) { if (bundle == null) { return new JSONObject(); }//from w ww .j a v a2 s . co m JSONObject j = new JSONObject(); Set<String> keys = bundle.keySet(); for (String key : keys) { try { Class<?> jsonClass = j.getClass(); Class[] cArg = new Class[1]; cArg[0] = String.class; //Workaround for API < 19 try { if (jsonClass.getDeclaredMethod("wrap", cArg) != null) { j.put(key, JSONObject.wrap(bundle.get(key))); } } catch (NoSuchMethodException e) { j.put(key, this._wrap(bundle.get(key))); } } catch (JSONException ex) { } } return j; }
From source file:com.github.jberkel.pay.me.IabHelper.java
int getResponseCodeFromBundle(Bundle bundle) { Object o;/*from w w w.ja va 2 s.c o m*/ if (bundle == null || (o = bundle.get(RESPONSE_CODE)) == null) { logDebug("Bundle with null response code, assuming OK (known issue)"); return OK.code; } else if (o instanceof Integer) return (Integer) o; // Workaround to bug where sometimes response codes come as Long instead of Integer else if (o instanceof Long) return (int) ((Long) o).longValue(); else { logError("Unexpected type for bundle response code."); logError(o.getClass().getName()); throw new RuntimeException("Unexpected type for bundle response code: " + o.getClass().getName()); } }
From source file:com.evandroid.musica.broadcastReceiver.MusicBroadcastReceiver.java
@Override public void onReceive(Context context, Intent intent) { /** Google Play Music //bool streaming long position //long albumId String album //bool currentSongLoaded String track //long ListPosition long ListSize //long id bool playing //long duration int previewPlayType //bool supportsRating int domain //bool albumArtFromService String artist //int rating bool local //bool preparing bool inErrorState *///from ww w . j av a 2 s . c om Bundle extras = intent.getExtras(); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context); boolean lengthFilter = sharedPref.getBoolean("pref_filter_20min", true); if (extras != null) try { extras.getInt("state"); } catch (BadParcelableException e) { return; } if (extras == null || extras.getInt("state") > 1 //Tracks longer than 20min are presumably not songs || (lengthFilter && (extras.get("duration") instanceof Long && extras.getLong("duration") > 1200000) || (extras.get("duration") instanceof Double && extras.getDouble("duration") > 1200000) || (extras.get("duration") instanceof Integer && extras.getInt("duration") > 1200)) || (lengthFilter && (extras.get("secs") instanceof Long && extras.getLong("secs") > 1200000) || (extras.get("secs") instanceof Double && extras.getDouble("secs") > 1200000) || (extras.get("secs") instanceof Integer && extras.getInt("secs") > 1200))) return; String artist = extras.getString("artist"); String track = extras.getString("track"); long position = extras.containsKey("position") ? extras.getLong("position") : -1; if (extras.get("position") instanceof Double) position = Double.valueOf(extras.getDouble("position")).longValue(); boolean isPlaying = extras.getBoolean("playing", true); if (intent.getAction().equals("com.amazon.mp3.metachanged")) { artist = extras.getString("com.amazon.mp3.artist"); track = extras.getString("com.amazon.mp3.track"); } else if (intent.getAction().equals("com.spotify.music.metadatachanged")) isPlaying = spotifyPlaying; else if (intent.getAction().equals("com.spotify.music.playbackstatechanged")) spotifyPlaying = isPlaying; if ((artist == null || "".equals(artist)) //Could be problematic || (track == null || "".equals(track) || track.startsWith("DTNS"))) // Ignore one of my favorite podcasts return; SharedPreferences current = context.getSharedPreferences("current_music", Context.MODE_PRIVATE); String currentArtist = current.getString("artist", ""); String currentTrack = current.getString("track", ""); SharedPreferences.Editor editor = current.edit(); editor.putString("artist", artist); editor.putString("track", track); editor.putLong("position", position); editor.putBoolean("playing", isPlaying); if (isPlaying) { long currentTime = System.currentTimeMillis(); editor.putLong("startTime", currentTime); } editor.apply(); autoUpdate = autoUpdate || sharedPref.getBoolean("pref_auto_refresh", false); int notificationPref = Integer.valueOf(sharedPref.getString("pref_notifications", "0")); if (autoUpdate && App.isActivityVisible()) { Intent internalIntent = new Intent("Broadcast"); internalIntent.putExtra("artist", artist).putExtra("track", track); LyricsViewFragment.sendIntent(context, internalIntent); forceAutoUpdate(false); } SQLiteDatabase db = new DatabaseHelper(context).getReadableDatabase(); boolean inDatabase = DatabaseHelper.presenceCheck(db, new String[] { artist, track, artist, track }); db.close(); if (notificationPref != 0 && isPlaying && (inDatabase || OnlineAccessVerifier.check(context))) { Intent activityIntent = new Intent("com.geecko.QuickLyric.getLyrics").putExtra("TAGS", new String[] { artist, track }); Intent wearableIntent = new Intent("com.geecko.QuickLyric.SEND_TO_WEARABLE").putExtra("artist", artist) .putExtra("track", track); PendingIntent openAppPending = PendingIntent.getActivity(context, 0, activityIntent, PendingIntent.FLAG_CANCEL_CURRENT); PendingIntent wearablePending = PendingIntent.getBroadcast(context, 8, wearableIntent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Action wearableAction = new NotificationCompat.Action.Builder(R.drawable.ic_watch, context.getString(R.string.wearable_prompt), wearablePending).build(); NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(context); NotificationCompat.Builder wearableNotifBuilder = new NotificationCompat.Builder(context); if ("0".equals(sharedPref.getString("pref_theme", "0"))) notifBuilder.setColor(context.getResources().getColor(R.color.primary)); notifBuilder.setSmallIcon(R.drawable.ic_notif).setContentTitle(context.getString(R.string.app_name)) .setContentText(String.format("%s - %s", artist, track)).setContentIntent(openAppPending) .setVisibility(-1) // Notification.VISIBILITY_SECRET .setGroup("Lyrics_Notification").setGroupSummary(true); wearableNotifBuilder.setSmallIcon(R.drawable.ic_notif) .setContentTitle(context.getString(R.string.app_name)) .setContentText(String.format("%s - %s", artist, track)).setContentIntent(openAppPending) .setVisibility(-1) // Notification.VISIBILITY_SECRET .setGroup("Lyrics_Notification").setOngoing(false).setGroupSummary(false) .extend(new NotificationCompat.WearableExtender().addAction(wearableAction)); if (notificationPref == 2) { notifBuilder.setOngoing(true).setPriority(-2); // Notification.PRIORITY_MIN } else notifBuilder.setPriority(-1); // Notification.PRIORITY_LOW Notification notif = notifBuilder.build(); Notification wearableNotif = wearableNotifBuilder.build(); if (notificationPref == 2) notif.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; else notif.flags |= Notification.FLAG_AUTO_CANCEL; NotificationManagerCompat.from(context).notify(0, notif); try { context.getPackageManager().getPackageInfo("com.google.android.wearable.app", PackageManager.GET_META_DATA); NotificationManagerCompat.from(context).notify(8, wearableNotif); } catch (PackageManager.NameNotFoundException ignored) { } } else if (track.equals(current.getString("track", ""))) NotificationManagerCompat.from(context).cancel(0); }
From source file:com.chess.genesis.data.GameDataDB.java
public void archiveNetworkGame(final String gameid, final int w_from, final int w_to, final int b_from, final int b_to) { final String[] data = { gameid }; final Bundle row = rowToBundle(db.rawQuery("SELECT * FROM onlinegames WHERE gameid=?", data), 0, true); final String tnames = "(gameid, gametype, eventtype, status, w_psrfrom, w_psrto, b_psrfrom, b_psrto, ctime, stime, ply, white, black, zfen, history)"; final String dstring = "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; final Object[] data2 = { row.get("gameid"), row.get("gametype"), row.get("eventtype"), row.get("status"), w_from, w_to, b_from, b_to, row.get("ctime"), row.get("stime"), row.get("ply"), row.get("white"), row.get("black"), row.get("zfen"), row.get("history") }; db.execSQL("INSERT OR REPLACE INTO archivegames " + tnames + " VALUES " + dstring + ';', data2); db.execSQL("DELETE FROM onlinegames WHERE gameid=?;", data); }
From source file:de.kuschku.quasseldroid_ng.ui.chat.MainActivity.java
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true) public void onEventMainThread(CoreSetupRequiredEvent event) { if (coreSetupCancelled) { finish();/*www. j a v a 2 s . c om*/ } else if (coreSetupResult != null) { context.provider().event.removeStickyEvent(CoreSetupRequiredEvent.class); Account account = manager.account(context.settings().preferenceLastAccount.get()); Bundle config = coreSetupResult.getBundle("config"); Map<String, QVariant> configData = new HashMap<>(); for (String key : config.keySet()) { configData.put(key, new QVariant<>(config.get(key))); } context.provider().dispatch(new HandshakeFunction(new CoreSetupData(new SetupData(account.user, account.pass, coreSetupResult.getString("selectedBackend"), configData)))); } else { Intent intent = new Intent(getApplicationContext(), CoreSetupActivity.class); intent.putExtra("storageBackends", context.client().core().getStorageBackendsAsBundle()); startActivityForResult(intent, REQUEST_CODE_CORESETUP); } }
From source file:li.klass.fhem.fragments.TimerDetailFragment.java
private void createSelectDeviceButton(View view) { Button selectDeviceButton = (Button) view.findViewById(R.id.targetDeviceSet); selectDeviceButton.setOnClickListener(new View.OnClickListener() { @Override//from www.j a v a 2 s . c om public void onClick(View view) { Intent intent = new Intent(Actions.SHOW_FRAGMENT); intent.putExtra(BundleExtraKeys.FRAGMENT, FragmentType.DEVICE_SELECTION); intent.putExtra(BundleExtraKeys.DEVICE_FILTER, deviceFilter); intent.putExtra(RESULT_RECEIVER, new FhemResultReceiver() { @Override protected void onReceiveResult(int resultCode, Bundle resultData) { if (resultCode != ResultCodes.SUCCESS) return; if (!resultData.containsKey(CLICKED_DEVICE)) return; updateTargetDevice((FhemDevice) resultData.get(CLICKED_DEVICE)); } }); getActivity().sendBroadcast(intent); } }); }
From source file:com.canappi.connector.yp.yhere.SettingsView.java
public void viewDidLoad() { Bundle extras = getIntent().getExtras(); if (extras != null) { Set<String> keys = extras.keySet(); for (Iterator<String> iter = keys.iterator(); iter.hasNext();) { String key = iter.next(); Class c = SearchView.class; try { Field f = c.getDeclaredField(key); Object extra = extras.get(key); String value = extra.toString(); f.set(this, extras.getString(value)); } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace();//from ww w .j a va 2s . co m } catch (NoSuchFieldException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } else { } settingsViewIds = new HashMap(); settingsViewValues = new HashMap(); isUserDefault = true; if (isUserDefault) { searchlocEditText.setText(retrieveFromUserDefaultsFor("searchloc"), TextView.BufferType.EDITABLE); } String updateZipButtonText = "Update"; String updateZipButtonPressedText = ""; updateZipButton = (Button) findViewById(R.id.updateZipButton); updateZipButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Perform action on click updateDefaults(v); } }); didSelectViewController(); }
From source file:com.breadwallet.presenter.activities.MainActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case BRConstants.PAY_REQUEST_CODE: if (resultCode == RESULT_OK) { PostAuthenticationProcessor.getInstance().onPublishTxAuth(this, true); }// www . j a va2s . c o m break; case BRConstants.PAYMENT_PROTOCOL_REQUEST_CODE: if (resultCode == RESULT_OK) { PostAuthenticationProcessor.getInstance().onPaymentProtocolRequest(this, true); } break; case BRConstants.REQUEST_IMAGE_CAPTURE: if (resultCode == RESULT_OK) { Bundle extras = data.getExtras(); Bitmap imageBitmap = (Bitmap) extras.get("data"); CameraPlugin.handleCameraImageTaken(this, imageBitmap); } else { CameraPlugin.handleCameraImageTaken(this, null); } break; case BRConstants.REQUEST_PHRASE_BITID: if (resultCode == RESULT_OK) { RequestHandler.processBitIdResponse(this); } break; } }
From source file:com.geecko.QuickLyric.broadcastReceiver.MusicBroadcastReceiver.java
@Override public void onReceive(Context context, Intent intent) { /** Google Play Music //bool streaming long position //long albumId String album //bool currentSongLoaded String track //long ListPosition long ListSize //long id bool playing //long duration int previewPlayType //bool supportsRating int domain //bool albumArtFromService String artist //int rating bool local //bool preparing bool inErrorState *///from ww w . j a v a 2 s . com Bundle extras = intent.getExtras(); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context); boolean lengthFilter = sharedPref.getBoolean("pref_filter_20min", true); if (extras != null) try { extras.getInt("state"); } catch (BadParcelableException e) { return; } if (extras == null || extras.getInt("state") > 1 //Tracks longer than 20min are presumably not songs || (lengthFilter && (extras.get("duration") instanceof Long && extras.getLong("duration") > 1200000) || (extras.get("duration") instanceof Double && extras.getDouble("duration") > 1200000) || (extras.get("duration") instanceof Integer && extras.getInt("duration") > 1200)) || (lengthFilter && (extras.get("secs") instanceof Long && extras.getLong("secs") > 1200000) || (extras.get("secs") instanceof Double && extras.getDouble("secs") > 1200000) || (extras.get("secs") instanceof Integer && extras.getInt("secs") > 1200)) || (extras.containsKey("com.maxmpz.audioplayer.source") && Build.VERSION.SDK_INT >= 19)) return; String artist = extras.getString("artist"); String track = extras.getString("track"); long position = extras.containsKey("position") && extras.get("position") instanceof Long ? extras.getLong("position") : -1; if (extras.get("position") instanceof Double) position = Double.valueOf(extras.getDouble("position")).longValue(); boolean isPlaying = extras.getBoolean(extras.containsKey("playstate") ? "playstate" : "playing", true); if (intent.getAction().equals("com.amazon.mp3.metachanged")) { artist = extras.getString("com.amazon.mp3.artist"); track = extras.getString("com.amazon.mp3.track"); } else if (intent.getAction().equals("com.spotify.music.metadatachanged")) isPlaying = spotifyPlaying; else if (intent.getAction().equals("com.spotify.music.playbackstatechanged")) spotifyPlaying = isPlaying; if ((artist == null || "".equals(artist)) //Could be problematic || (track == null || "".equals(track) || track.startsWith("DTNS"))) // Ignore one of my favorite podcasts return; SharedPreferences current = context.getSharedPreferences("current_music", Context.MODE_PRIVATE); String currentArtist = current.getString("artist", ""); String currentTrack = current.getString("track", ""); SharedPreferences.Editor editor = current.edit(); editor.putString("artist", artist); editor.putString("track", track); if (!(artist.equals(currentArtist) && track.equals(currentTrack) && position == -1)) editor.putLong("position", position); editor.putBoolean("playing", isPlaying); if (isPlaying) { long currentTime = System.currentTimeMillis(); editor.putLong("startTime", currentTime); } editor.apply(); autoUpdate = autoUpdate || sharedPref.getBoolean("pref_auto_refresh", false); int notificationPref = Integer.valueOf(sharedPref.getString("pref_notifications", "0")); if (autoUpdate && App.isActivityVisible()) { Intent internalIntent = new Intent("Broadcast"); internalIntent.putExtra("artist", artist).putExtra("track", track); LyricsViewFragment.sendIntent(context, internalIntent); forceAutoUpdate(false); } boolean inDatabase = DatabaseHelper.getInstance(context) .presenceCheck(new String[] { artist, track, artist, track }); if (notificationPref != 0 && isPlaying && (inDatabase || OnlineAccessVerifier.check(context))) { Intent activityIntent = new Intent("com.geecko.QuickLyric.getLyrics").putExtra("TAGS", new String[] { artist, track }); Intent wearableIntent = new Intent("com.geecko.QuickLyric.SEND_TO_WEARABLE").putExtra("artist", artist) .putExtra("track", track); PendingIntent openAppPending = PendingIntent.getActivity(context, 0, activityIntent, PendingIntent.FLAG_CANCEL_CURRENT); PendingIntent wearablePending = PendingIntent.getBroadcast(context, 8, wearableIntent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Action wearableAction = new NotificationCompat.Action.Builder(R.drawable.ic_watch, context.getString(R.string.wearable_prompt), wearablePending).build(); NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(context); NotificationCompat.Builder wearableNotifBuilder = new NotificationCompat.Builder(context); int[] themes = new int[] { R.style.Theme_QuickLyric, R.style.Theme_QuickLyric_Red, R.style.Theme_QuickLyric_Purple, R.style.Theme_QuickLyric_Indigo, R.style.Theme_QuickLyric_Green, R.style.Theme_QuickLyric_Lime, R.style.Theme_QuickLyric_Brown, R.style.Theme_QuickLyric_Dark }; int themeNum = Integer.valueOf(sharedPref.getString("pref_theme", "0")); TypedValue primaryColorValue = new TypedValue(); context.setTheme(themes[themeNum]); context.getTheme().resolveAttribute(R.attr.colorPrimary, primaryColorValue, true); notifBuilder.setSmallIcon(R.drawable.ic_notif).setContentTitle(context.getString(R.string.app_name)) .setContentText(String.format("%s - %s", artist, track)).setContentIntent(openAppPending) .setVisibility(-1) // Notification.VISIBILITY_SECRET .setGroup("Lyrics_Notification").setColor(primaryColorValue.data).setGroupSummary(true); wearableNotifBuilder.setSmallIcon(R.drawable.ic_notif) .setContentTitle(context.getString(R.string.app_name)) .setContentText(String.format("%s - %s", artist, track)).setContentIntent(openAppPending) .setVisibility(-1) // Notification.VISIBILITY_SECRET .setGroup("Lyrics_Notification").setOngoing(false).setColor(primaryColorValue.data) .setGroupSummary(false) .extend(new NotificationCompat.WearableExtender().addAction(wearableAction)); if (notificationPref == 2) { notifBuilder.setOngoing(true).setPriority(-2); // Notification.PRIORITY_MIN wearableNotifBuilder.setPriority(-2); } else notifBuilder.setPriority(-1); // Notification.PRIORITY_LOW Notification notif = notifBuilder.build(); Notification wearableNotif = wearableNotifBuilder.build(); if (notificationPref == 2) notif.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; else notif.flags |= Notification.FLAG_AUTO_CANCEL; NotificationManagerCompat.from(context).notify(0, notif); try { context.getPackageManager().getPackageInfo("com.google.android.wearable.app", PackageManager.GET_META_DATA); NotificationManagerCompat.from(context).notify(8, wearableNotif); } catch (PackageManager.NameNotFoundException ignored) { } } else if (track.equals(current.getString("track", ""))) NotificationManagerCompat.from(context).cancel(0); }