List of usage examples for android.os Bundle get
@Nullable
public Object get(String key)
From source file:com.eleybourn.bookcatalogue.utils.Utils.java
/** * Get a value from a bundle and convert to a long. * /*from ww w. j a va 2 s . c o m*/ * @param b Bundle * @param key Key in bundle * * @return Result */ public static String getAsString(Bundle b, String key) { Object o = b.get(key); return o.toString(); }
From source file:edu.mit.mobile.android.locast.data.Sync.java
private void sync(Uri toSync, SyncProgressNotifier syncProgress, Bundle extras) throws SyncException, IOException { Uri localUri;//from ww w .j av a 2 s.com if ("http".equals(toSync.getScheme()) || "https".equals(toSync.getScheme())) { if (!extras.containsKey(EXTRA_DESTINATION_URI)) { throw new IllegalArgumentException("missing EXTRA_DESTINATION_URI when syncing HTTP URIs"); } localUri = (Uri) extras.get(EXTRA_DESTINATION_URI); if (!MediaProvider.canSync(localUri)) { throw new IllegalArgumentException("URI " + toSync + " is not syncable."); } } else { localUri = toSync; } if (!MediaProvider.canSync(localUri)) { throw new IllegalArgumentException("URI " + toSync + " is not syncable."); } sync(toSync, getSyncItem(localUri), syncProgress, extras); }
From source file:com.eleybourn.bookcatalogue.utils.Utils.java
/** * Get a value from a bundle and convert to a long. * // w w w .j ava 2 s.c o m * @param b Bundle * @param key Key in bundle * * @return Result */ public static long getAsLong(Bundle b, String key) { Object o = b.get(key); if (o instanceof Long) { return (Long) o; } else if (o instanceof String) { return Long.parseLong((String) o); } else if (o instanceof Integer) { return ((Integer) o).longValue(); } else { throw new RuntimeException("Not a long value"); } }
From source file:com.abbiya.broadr.gcm.GcmIntentService.java
@Override protected void onHandleIntent(Intent intent) { JobManager jobManager = BroadrApp.getInstance().getJobManager(); Bundle extras = intent.getExtras(); GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); // The getMessageType() intent parameter must be the intent you received // in your BroadcastReceiver. String messageType = gcm.getMessageType(intent); if (!extras.isEmpty()) { // has effect of unparcelling Bundle /*/* ww w . j ava 2 s .c o m*/ * Filter messages based on message type. Since it is likely that GCM will be * extended in the future with new message types, just ignore any message types you're * not interested in, or that you don't recognize. */ if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { //retry sending String messageId = (String) extras.get("google.message_id"); String uuid = null; Integer msgType = null; if (messageId != null) { if (messageId.startsWith(Constants.MESSAGE_PREFIX)) { uuid = messageId.substring(Constants.MESSAGE_PREFIX.length(), messageId.length()); msgType = Constants.MESSAGE; } else if (messageId.startsWith(Constants.COMMENT_PREFIX)) { uuid = messageId.substring(Constants.COMMENT_PREFIX.length(), messageId.length()); msgType = Constants.COMMENT; } else if (messageId.startsWith(Constants.GCM_REGISTRATION)) { String email = BroadrApp.getSharedPreferences().getString(Constants.USER_EMAIL, ""); jobManager.addJobInBackground( new SendRegistrationMessageJob(email, UUID.randomUUID().toString())); } else if (messageId != null && messageId.startsWith(Constants.LOCATION_PREFIX)) { String geoHash = LocationUtils.getGeoHash(); GeoHash from = GeoHash.fromGeohashString(geoHash); WGS84Point point = from.getPoint(); Double startLatitude = point.getLatitude(); Double startLongitude = point.getLongitude(); SharedPreferences sharedPreferences = BroadrApp.getSharedPreferences(); String address = sharedPreferences.getString(Constants.LAST_KNOWN_ADDRESS, ""); jobManager.addJobInBackground(new SendLocationJob(String.valueOf(startLatitude), String.valueOf(startLongitude), address, UUID.randomUUID().toString())); } } if (uuid != null) { if (msgType == Constants.MESSAGE) { MessageRepo messageRepo = BroadrApp.getMessageRepo(); Message message = messageRepo.getMessage(uuid); if (message != null) { jobManager.addJobInBackground( new SendMessageJob(message.getId(), message.getContent(), message.getUuid())); } } else if (msgType == Constants.COMMENT) { CommentRepo commentRepo = BroadrApp.getCommentRepo(); Comment comment = commentRepo.getComment(uuid); if (comment != null) { jobManager.addJobInBackground( new SendCommentJob(comment.getId(), comment.getContent(), comment.getUuid())); } } } else { //sendNotification("Send error: " + extras.toString()); } } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { sendNotification("Deleted messages on server: " + extras.toString(), NOTIFICATION_ID); // If it's a regular GCM message, do some work. } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { //parse the message and do db operations post the event //Post notification of received message. String receivedMessageType = extras.getString("t"); String messageId = null; MessageRepo messageRepo = BroadrApp.getMessageRepo(); CommentRepo commentRepo = BroadrApp.getCommentRepo(); Message message = null; Comment comment = null; if (null != extras.get("m_id")) { messageId = String.valueOf(extras.get("m_id")); } //check the message id prefix and find the comment or message if (messageId != null && messageId.startsWith(Constants.MESSAGE_PREFIX)) { messageId = messageId.substring(Constants.MESSAGE_PREFIX.length()); message = messageRepo.getMessage(messageId); } else if (messageId != null && messageId.startsWith(Constants.COMMENT_PREFIX)) { messageId = messageId.substring(Constants.COMMENT_PREFIX.length()); comment = commentRepo.getComment(messageId); } else if (messageId != null && messageId.startsWith(Constants.GCM_REGISTRATION)) { EventBus.getDefault().post(new SentRegistrationMessageEvent()); } else if (messageId != null && messageId.startsWith(Constants.LOCATION_PREFIX)) { EventBus.getDefault().post(new SentLocationEvent()); } if (extras.get("o") != null) { sendNotification(String.valueOf(extras.get("o")), 2); } if (message == null) { int type = 0; if (receivedMessageType != null) { switch (receivedMessageType.charAt(0)) { case 'r': type = 0; break; case 'l': type = 1; break; case 'm': type = 2; //received from gcm by others String content = String.valueOf(extras.get("c")); String geoHash = String.valueOf(extras.get("l")); String uuid = String.valueOf(extras.get("s_id")); message = messageRepo.getMessage(uuid); if (message == null) { message = new Message(content, new Date(), geoHash); message.setType(Constants.MESSAGE); message.setUpdatedAt(new Date()); message.setStatus(Constants.RECEIVED_GCM); message.setUuid(uuid); Board currentBoard = (Board) AppSingleton.getObj(Constants.CURRENT_BOARD_OBJ); if (currentBoard == null) { String board = BroadrApp.getSharedPreferences().getString(Constants.LAST_BOARD, null); if (board != null && board.length() >= 4) { currentBoard = BroadrApp.getBoardRepo().getBoard(board.substring(0, 4)); } } if (message.getHappenedAt().getTime() > new Date().getTime()) { message.setHappenedAt(new Date()); } message.setBoard(currentBoard); messageRepo.insertOrReplace(message); EventBus.getDefault().post(new SavedReceivedMessagesEvent()); EventBus.getDefault().post(new ReceivedGCMMessageEvent(message)); long when = Long.valueOf(BroadrApp.getSettingsPreferences() .getString(SettingsActivity.NOTIF_PERIOD, "1")).longValue(); if (when == 1) { checkNumberOfReceivedMessagesTillNowAndNotify(false); } } break; case 'c': type = 3; break; case 'a': type = 5; break; default: type = 0; break; } if (receivedMessageType.equals("lk")) { type = 4; } } } else { //this guy's message message.setUpdatedAt(new Date()); message.setStatus(Constants.DELIVERED); messageRepo.updateMessage(message); //message sent event EventBus.getDefault().post(new DeliveredRavenEvent(message)); mNotificationManager.cancel(StringUtilities.safeLongToInt(message.getId())); } if (comment != null) { comment.setHappenedAt(new Date()); comment.setUpdatedAt(new Date()); comment.setStatus(Constants.DELIVERED); commentRepo.updateComment(comment); //comment sent event EventBus.getDefault().post(new CommentDeliveredEvent(comment)); } } else { Log.d(Constants.APPTAG, messageType); //sendNotification(messageType); } } // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); }
From source file:general.me.edu.dgtmovil.dgtmovil.formregisestudiante.FormEstudDosFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { try {//from www. j av a2s .c o m if (requestCode == SIGNATURE_ACTIVITY && resultCode == CaptureSignature.RESULT_OK) { Bitmap imagenFirma = null; Bundle bundle = data.getExtras(); String status = bundle.getString("status"); if (status.equalsIgnoreCase("done")) { //DATO PARA ALMACENAR EN LA BD datoBdFirma = bundle.getString("imagen"); try { imagenFirma = BitmapFactory.decodeStream(getActivity().openFileInput(datoBdFirma)); datoBdFirma = codificarImagen(imagenFirma); // imagenFirma.toString();//createImageFromBitmap(imagenFirma); } catch (FileNotFoundException e) { e.printStackTrace(); } // firma.setImageBitmap(imagenFirma); Drawable dra = new BitmapDrawable(getResources(), imagenFirma); firma.setImageDrawable(dra); // firma.setBackground(Drawable.createFromPath(String.valueOf(imagenFirma))); Toast toast = Toast.makeText(getActivity(), "Signature capture successful!", Toast.LENGTH_SHORT); toast.setGravity(Gravity.TOP, 105, 50); toast.show(); } } } catch (Exception e) { } //PARA RECIBIR LA FOTO DE LA CAMARA try { if (resultCode == getActivity().RESULT_OK && requestCode == CONS) { Bundle ext = data.getExtras(); bmpFoto = (Bitmap) ext.get("data"); Drawable dra = new BitmapDrawable(getResources(), bmpFoto); btnFoto.setImageDrawable(dra); //DATO PARA LA BASE DE DATOS datoBdFoto = codificarImagen(bmpFoto); } } catch (Exception e) { } if (requestCode == MY_REQUEST_CODE && resultCode == Pdf417ScanActivity.RESULT_OK) { // First, obtain recognition result RecognitionResults results = data.getParcelableExtra(Pdf417ScanActivity.EXTRAS_RECOGNITION_RESULTS); // Get scan results array. If scan was successful, array will contain at least one element. // Multiple element may be in array if multiple scan results from single image were allowed in settings. BaseRecognitionResult[] resultArray = results.getRecognitionResults(); // Each recognition result corresponds to active recognizer. As stated earlier, there are 4 types of // recognizers available (PDF417, Bardecoder, ZXing and USDL), so there are 4 types of results // available. StringBuilder sb = new StringBuilder(); for (BaseRecognitionResult res : resultArray) { if (res instanceof Pdf417ScanResult) { // check if scan result is result of Pdf417 recognizer result = (Pdf417ScanResult) res; // getStringData getter will return the string version of barcode contents String barcodeData = result.getStringData(); // isUncertain getter will tell you if scanned barcode contains some uncertainties boolean uncertainData = result.isUncertain(); // getRawData getter will return the raw data information object of barcode contents BarcodeDetailedData rawData = result.getRawData(); // BarcodeDetailedData contains information about barcode's binary layout, if you // are only interested in raw bytes, you can obtain them with getAllData getter byte[] rawDataBuffer = rawData.getAllData(); // if data is URL, open the browser and stop processing result if (checkIfDataIsUrlAndCreateIntent(barcodeData)) { return; } else { // add data to string builder sb.append("PDF417 scan data"); if (uncertainData) { sb.append("This scan data is uncertain!\n\n"); } sb.append(" string data:\n"); sb.append(barcodeData); if (rawData != null) { sb.append("\n\n"); sb.append("PDF417 raw data:\n"); sb.append(rawData.toString()); sb.append("\n"); sb.append("PDF417 raw data merged:\n"); sb.append("{"); for (int i = 0; i < rawDataBuffer.length; ++i) { sb.append((int) rawDataBuffer[i] & 0x0FF); if (i != rawDataBuffer.length - 1) { sb.append(", "); } } BarcodeElement[] dato = rawData.getElements(); // Toast.makeText(DatosActivity.this, "Datos: "+mostrar[5], Toast.LENGTH_LONG).show(); String[] datos = deco.decodificarCedula(rawData.toString()); for (int i = 0; i < datos.length; i++) { if (datos[i] == null) { datos[i] = " "; } } FormEstudUnoFragment.p2.setText(datos[1] + " " + datos[2]); FormEstudUnoFragment.p1.setText(datos[3] + " " + datos[4]); FormEstudUnoFragment.p4.setText(datos[0]); FormEstudUnoFragment.p5.setText(datos[5]); sb.append("}\n\n\n"); } } } else if (res instanceof BarDecoderScanResult) { // check if scan result is result of BarDecoder recognizer BarDecoderScanResult result = (BarDecoderScanResult) res; // with getBarcodeType you can obtain barcode type enum that tells you the type of decoded barcode BarcodeType type = result.getBarcodeType(); // as with PDF417, getStringData will return the string contents of barcode String barcodeData = result.getStringData(); if (checkIfDataIsUrlAndCreateIntent(barcodeData)) { return; } else { sb.append(type.name()); sb.append(" string data:\n"); sb.append(barcodeData); sb.append("\n\n\n"); } } else if (res instanceof ZXingScanResult) { // check if scan result is result of ZXing recognizer ZXingScanResult result = (ZXingScanResult) res; // with getBarcodeType you can obtain barcode type enum that tells you the type of decoded barcode BarcodeType type = result.getBarcodeType(); // as with PDF417, getStringData will return the string contents of barcode String barcodeData = result.getStringData(); if (checkIfDataIsUrlAndCreateIntent(barcodeData)) { return; } else { sb.append(type.name()); sb.append(" string data:\n"); sb.append(barcodeData); sb.append("\n\n\n"); } } else if (res instanceof USDLScanResult) { // check if scan result is result of US Driver's Licence recognizer USDLScanResult result = (USDLScanResult) res; // USDLScanResult can contain lots of information extracted from driver's licence // you can obtain information using the getField method with keys defined in // USDLScanResult class String name = result.getField(USDLScanResult.kCustomerFullName); Log.i(TAG, "Customer full name is " + name); sb.append(result.getTitle()); sb.append("\n\n"); sb.append(result.toString()); } } Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, sb.toString()); startActivity(Intent.createChooser(intent, getString(R.string.UseWith))); } }
From source file:com.android.launcher3.Utilities.java
/** * Returns true if {@param original} contains all entries defined in {@param updates} and * have the same value.//w w w.j ava 2 s . c o m * 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; }
From source file:com.canappi.connector.yp.yhere.HomeView.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();/*w ww. ja v a2 s. 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 { } homeViewIds = new HashMap(); homeViewValues = new HashMap(); isUserDefault = false; String restaurantButtonText = ""; String restaurantButtonPressedText = ""; restaurantButton = (Button) findViewById(R.id.restaurantButton); restaurantButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Perform action on click goToRestaurantView(v); } }); String groceryButtonText = ""; String groceryButtonPressedText = ""; groceryButton = (Button) findViewById(R.id.groceryButton); groceryButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Perform action on click goToGroceryView(v); } }); String gasButtonText = ""; String gasButtonPressedText = ""; gasButton = (Button) findViewById(R.id.gasButton); gasButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Perform action on click goToGasView(v); } }); String teatherButtonText = ""; String teatherButtonPressedText = ""; teatherButton = (Button) findViewById(R.id.teatherButton); teatherButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Perform action on click goToTeatherView(v); } }); String couponButtonText = ""; String couponButtonPressedText = ""; couponButton = (Button) findViewById(R.id.couponButton); couponButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Perform action on click goToCouponView(v); } }); String lubeButtonText = ""; String lubeButtonPressedText = ""; lubeButton = (Button) findViewById(R.id.lubeButton); lubeButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Perform action on click goToLubeView(v); } }); String gameButtonText = ""; String gameButtonPressedText = ""; gameButton = (Button) findViewById(R.id.gameButton); gameButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Perform action on click goGameView(v); } }); String bakeryButtonText = ""; String bakeryButtonPressedText = ""; bakeryButton = (Button) findViewById(R.id.bakeryButton); bakeryButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Perform action on click goToBakeryView(v); } }); String repairButtonText = ""; String repairButtonPressedText = ""; repairButton = (Button) findViewById(R.id.repairButton); repairButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Perform action on click goToRepairView(v); } }); if (isUserDefault) { termEditText.setText(retrieveFromUserDefaultsFor("term"), TextView.BufferType.EDITABLE); } String findButtonText = "Search"; String findButtonPressedText = ""; findButton = (Button) findViewById(R.id.findButton); findButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Perform action on click goToSearchView(v); } }); didSelectViewController(); }
From source file:org.pixmob.appengine.client.AppEngineClient.java
private String getAuthToken() throws AppEngineAuthenticationException { // get an authentication token from the AccountManager: // this call is asynchronous, as the user may not respond immediately final AccountManagerFuture<Bundle> futureBundle = accountManager.getAuthToken(account, "ah", true, null, null);//from w ww . ja va 2 s . c o m final Bundle authBundle; try { authBundle = futureBundle.getResult(); } catch (OperationCanceledException e) { throw new AppEngineAuthenticationException(AUTHENTICATION_UNAVAILABLE, e); } catch (AuthenticatorException e) { throw new AppEngineAuthenticationException(AUTHENTICATION_UNAVAILABLE, e); } catch (IOException e) { throw new AppEngineAuthenticationException(AUTHENTICATION_UNAVAILABLE, e); } final String authToken = authBundle.getString(AccountManager.KEY_AUTHTOKEN); if (authToken == null) { // no authentication token was given: the user should give its // permission through an item in the notification bar Log.i(TAG, "Authentication permission is required"); final Intent authPermIntent = (Intent) authBundle.get(AccountManager.KEY_INTENT); int flags = authPermIntent.getFlags(); flags &= ~Intent.FLAG_ACTIVITY_NEW_TASK; authPermIntent.setFlags(flags); throw new AppEngineAuthenticationException(AUTHENTICATION_PENDING, authPermIntent); } return authToken; }
From source file:com.josetomastocino.siteupclient.app.GcmIntentService.java
@Override protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras(); GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); // The getMessageType() intent parameter must be the intent you received // in your BroadcastReceiver. String messageType = gcm.getMessageType(intent); if (!extras.isEmpty()) { // has effect of unparcelling Bundle /*//w w w .j av a 2 s .co m * Filter messages based on message type. Since it is likely that GCM will be * extended in the future with new message types, just ignore any message types you're * not interested in, or that you don't recognize. */ if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { sendNotification("Send error: " + extras.toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { sendNotification("Deleted messages on server: " + extras.toString()); // If it's a regular GCM message, do some work. } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { // Post notification of received message. sendNotification(extras.get("message").toString()); Log.i(TAG, "Received: " + extras.toString()); } } // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); }
From source file:com.phonegap.DroidGap.java
/** * Get double property for activity.//from w w w. j a va 2 s .c om * * @param name * @param defaultValue * @return */ public double getDoubleProperty(String name, double defaultValue) { Bundle bundle = this.getIntent().getExtras(); if (bundle == null) { return defaultValue; } Double p = (Double) bundle.get(name); if (p == null) { return defaultValue; } return p.doubleValue(); }