List of usage examples for android.content Intent getParcelableExtra
public <T extends Parcelable> T getParcelableExtra(String name)
From source file:com.asalfo.wiulgi.service.UtilityService.java
/** * Called when the location has been updated *//*w w w . j a va 2 s .c o m*/ private void locationUpdated(@NonNull Intent intent) { Log.v(TAG, ACTION_LOCATION_UPDATED); // Extra new location Location location = intent.getParcelableExtra(FusedLocationProviderApi.KEY_LOCATION_CHANGED); if (location != null) { LatLng latLngLocation = new LatLng(location.getLatitude(), location.getLongitude()); // Store in a local preference as well Utils.storeLocation(this, latLngLocation); // Send a local broadcast so if an Activity is open it can respond // to the updated location LocalBroadcastManager.getInstance(this).sendBroadcast(intent); } }
From source file:com.hybris.mobile.activity.NFCWriteActivity.java
@Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); // default failed setResult(RESULT_CANCELED);//from www. ja va2 s .co m if (NFCUtil.supportsNdef(tag)) { Ndef ndef = Ndef.get(tag); try { int maxSize = ndef.getMaxSize(); int messageSize = this.msg.toByteArray().length; if (ndef.isWritable() && maxSize > messageSize) { ndef.connect(); ndef.writeNdefMessage(this.msg); if (getResources().getBoolean(R.bool.nfc_read_only)) { if (ndef.canMakeReadOnly()) { boolean success = ndef.makeReadOnly(); if (!success) Toast.makeText(this, "Unable to make tag readonly!", Toast.LENGTH_LONG).show(); else Toast.makeText(this, "Tag is now readonly!", Toast.LENGTH_LONG).show(); } else { Toast.makeText(this, "This tag cannot be made readonly!", Toast.LENGTH_LONG).show(); } } setResult(RESULT_OK); showDialogFragmentWithMessage(R.string.nfc_tag_written); } else { showDialogFragmentWithMessage(R.string.error_nfc_readonly_size); } } catch (IOException e) { LoggingUtils.e(LOG_CAT, getString(R.string.error_nfc_io), e, Hybris.getAppContext()); } catch (FormatException e) { LoggingUtils.e(LOG_CAT, getString(R.string.error_nfc_format), e, Hybris.getAppContext()); } finally { try { ndef.close(); } catch (IOException e) { } } } else if (NFCUtil.supportsNdefFormatable(tag)) { NdefFormatable ndefFormatable = NdefFormatable.get(tag); try { ndefFormatable.connect(); if (getResources().getBoolean(R.bool.nfc_read_only)) { ndefFormatable.formatReadOnly(this.msg); } else { ndefFormatable.format(this.msg); } setResult(RESULT_OK); showDialogFragmentWithMessage(R.string.nfc_tag_written); } catch (IOException e) { LoggingUtils.e(LOG_CAT, getString(R.string.error_nfc_io), e, Hybris.getAppContext()); } catch (FormatException e) { LoggingUtils.e(LOG_CAT, getString(R.string.error_nfc_format), e, Hybris.getAppContext()); } finally { try { ndefFormatable.close(); } catch (IOException e) { } } } else { showDialogFragmentWithMessage(R.string.error_nfc_no_ndef); } }
From source file:com.github.luluvise.droid_utils.lib.network.NetworkBroadcastReceiver.java
@Override public void onReceive(Context context, Intent intent) { if (DroidConfig.DEBUG) { // debugging network info final NetworkInfo otherNetworkInfo = (NetworkInfo) intent .getParcelableExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO); final String reason = intent.getStringExtra(ConnectivityManager.EXTRA_REASON); final boolean failover = intent.getBooleanExtra(ConnectivityManager.EXTRA_IS_FAILOVER, false); Log.i(TAG,/*from w ww.j a v a 2s . c o m*/ "onReceive(): " + " otherNetworkInfo = " + (otherNetworkInfo == null ? "[none]" : otherNetworkInfo) + ", failover=" + failover + ", reason=" + reason); } // use EXTRA_NO_CONNECTIVITY to check if there is no connection if (intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false)) { notifyConnectionGone(context); return; } final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo netInfo = cm.getActiveNetworkInfo(); // send local broadcast to notify all registered receivers if (netInfo != null && netInfo.isConnected()) { // connection active notifyConnectionActive(context, netInfo.getType()); } else { // connection has gone notifyConnectionGone(context); } }
From source file:anakiou.com.picontrol.service.OutputIntentService.java
@Override protected void onHandleIntent(Intent intent) { receiver = intent.getParcelableExtra(Constants.RECEIVER); if (!networkService.isNetworkAvailableAndConnected()) { deliverResultToReceiver(Constants.FAILURE_RESULT, getString(R.string.network_required_msg)); return;//from www . j av a 2 s . co m } int operationType = intent.getIntExtra(Constants.EXTRA_OPERATION_TYPE, 0); switch (operationType) { case Constants.OP_OUTPUT_GET: handleGet(); break; case Constants.OP_OUTPUT_STATUS_ALL_GET: handleStatusAllGet(); break; case Constants.OP_OUTPUT_NAME_SET: handleNameSet(intent); break; case Constants.OP_OUTPUT_SINGLE_CONTROL: handleSingleControl(intent); break; case Constants.OP_OUTPUT_CONTROL_ALL: handleControlAll(intent); break; } }
From source file:com.saulcintero.moveon.services.MediaButtonEventReceiver.java
@Override public void onReceive(Context mContext, Intent intent) { String intentAction = intent.getAction(); if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intentAction)) { } else if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) { KeyEvent event = (KeyEvent) intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); if (event == null) return; if (event.getAction() == KeyEvent.ACTION_UP) { Intent i = new Intent("android.intent.action.ACTION_SAY_PRACTICE_INFORMATION"); i.putExtra("type", String.valueOf(NotificationTypes.TIME.getTypes())); mContext.sendBroadcast(i);// w w w. ja v a2s . c o m } } }
From source file:com.gmail.taneza.ronald.carbs.myfoods.MyFoodDetailsActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my_food_details); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mFoodDbAdapter = ((CarbsApp) getApplication()).getFoodDbAdapter(); // Get the message from the intent Intent intent = getIntent(); mFoodItem = intent.getParcelableExtra(MY_FOOD_ITEM_MESSAGE); FoodItemInfo foodItemInfo;/*from ww w .j a v a 2 s. c om*/ Mode mode = Mode.values()[intent.getIntExtra(MY_FOOD_ACTIVITY_MODE_MESSAGE, Mode.NewFood.ordinal())]; mMode = mode; if (mode == Mode.NewFood) { foodItemInfo = new FoodItemInfo(mFoodItem, NEW_FOOD_DEFAULT_NAME, NEW_FOOD_DEFAULT_QUANTITY_PER_UNIT, NEW_FOOD_DEFAULT_CARBS, NEW_FOOD_DEFAULT_UNIT_TEXT); } else { foodItemInfo = mFoodDbAdapter.getFoodItemInfo(mFoodItem); setTitle(R.string.title_activity_my_food_edit); Button okButton = (Button) findViewById(R.id.my_food_ok_button); okButton.setText(R.string.save_food_details); } mFoodNameTextView = (TextView) findViewById(R.id.my_food_name); mFoodNameTextView.setText(foodItemInfo.getName()); // Request focus and show soft keyboard automatically mFoodNameTextView.requestFocus(); getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE); mQuantityEditText = (EditText) findViewById(R.id.my_food_quantity_edit); mQuantityEditText.setText(Integer.toString(foodItemInfo.getQuantityPerUnit())); mQuantityUnitTextSpinner = (Spinner) findViewById(R.id.my_food_quantity_unit_spinner); // Create an ArrayAdapter using the string array and a default spinner layout ArrayAdapter<CharSequence> arrayAdapter = ArrayAdapter.createFromResource(this, R.array.quantity_unit_text_array, android.R.layout.simple_spinner_item); // Specify the layout to use when the list of choices appears arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Apply the adapter to the spinner mQuantityUnitTextSpinner.setAdapter(arrayAdapter); mQuantityUnitTextSpinner.setSelection(arrayAdapter.getPosition(foodItemInfo.getUnitText())); mNumCarbsTextView = (TextView) findViewById(R.id.my_food_carbs); // Display decimal place only when non-zero, so it's easier to edit String numCarbsString; float numCarbs = foodItemInfo.getNumCarbsInGrams(); if (numCarbs == (int) numCarbs) { numCarbsString = String.format(Locale.getDefault(), "%.0f", numCarbs); } else { numCarbsString = String.format(Locale.getDefault(), "%.1f", numCarbs); } mNumCarbsTextView.setText(numCarbsString); }
From source file:com.gsma.rcs.ri.messaging.chat.single.SingleChatIntentService.java
private void handleUndeliveredMessage(Intent intent, String msgId) { ContactId contact = intent.getParcelableExtra(OneToOneChatIntent.EXTRA_CONTACT); if (contact == null) { if (LogUtils.isActive) { Log.e(LOGTAG, "Cannot read contact for message ID=".concat(msgId)); }/*w w w . j ava 2 s .com*/ return; } if (LogUtils.isActive) { Log.d(LOGTAG, "Undelivered message ID=" + msgId + " for contact " + contact); } forwardUndeliveredMessage2UI(intent, contact); }
From source file:com.gmail.taneza.ronald.carbs.main.FoodDetailsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_food_details); getSupportActionBar().setDisplayHomeAsUpEnabled(true); // Get the message from the intent Intent intent = getIntent(); FoodItem foodItem = intent.getParcelableExtra(FOOD_ITEM_MESSAGE); Mode mode = Mode.values()[intent.getIntExtra(ACTIVITY_MODE_MESSAGE, Mode.NewFood.ordinal())]; // Create a copy of the foodItemInfo returned by foodDbAdapter, // because the user may modify the quantity value, and then cancel his changes. FoodDbAdapter foodDbAdapter = ((CarbsApp) getApplication()).getFoodDbAdapter(); FoodItemInfo foodItemInfo = foodDbAdapter.getFoodItemInfo(foodItem); mFoodItemInfo = new FoodItemInfo(foodItem, foodItemInfo.getName(), foodItemInfo.getQuantityPerUnit(), foodItemInfo.getNumCarbsInGramsPerUnit(), foodItemInfo.getUnitText()); TextView foodNameTextView = (TextView) findViewById(R.id.food_details_name); foodNameTextView.setText(mFoodItemInfo.getName()); TextView foodNameExtraTextView = (TextView) findViewById(R.id.food_details_name_extra); foodNameExtraTextView//from w w w .j a va 2 s . c o m .setText(String.format("(%.1f g carbs per %d %s)", mFoodItemInfo.getNumCarbsInGramsPerUnit(), mFoodItemInfo.getQuantityPerUnit(), mFoodItemInfo.getUnitText())); mQuantityEditText = (EditText) findViewById(R.id.food_details_quantity_edit); mQuantityEditText.setText(Integer.toString(mFoodItemInfo.getQuantity())); // Request focus and show soft keyboard automatically mQuantityEditText.requestFocus(); getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE); TextView quantityUnitTextView = (TextView) findViewById(R.id.food_details_quantity_unit); quantityUnitTextView.setText(mFoodItemInfo.getUnitText()); mNumCarbsTextView = (TextView) findViewById(R.id.food_details_carbs_text); updateCarbsText(); mMode = mode; if (mode == Mode.EditFoodInMeal) { setTitle(R.string.title_activity_food_details_edit); Button okButton = (Button) findViewById(R.id.food_details_ok_button); okButton.setText(R.string.save_food_details); mDeleteItemConfirmationStringId = R.string.delete_item_from_meal_confirmation; mItemDeletedMessageId = R.string.food_deleted_from_meal; } else if (mode == Mode.RecentFood) { mDeleteItemConfirmationStringId = R.string.delete_item_from_recent_foods_confirmation; mItemDeletedMessageId = R.string.food_deleted_from_recent; } addQuantityTextListener(); }
From source file:com.commonsware.andprojector.ProjectorService.java
@Override public int onStartCommand(Intent i, int flags, int startId) { projection = mgr.getMediaProjection(i.getIntExtra(EXTRA_RESULT_CODE, -1), (Intent) i.getParcelableExtra(EXTRA_RESULT_INTENT)); it = new ImageTransmogrifier(this); MediaProjection.Callback cb = new MediaProjection.Callback() { @Override//from w ww . jav a2 s . c o m public void onStop() { vdisplay.release(); } }; vdisplay = projection.createVirtualDisplay("andprojector", it.getWidth(), it.getHeight(), getResources().getDisplayMetrics().densityDpi, VIRT_DISPLAY_FLAGS, it.getSurface(), null, handler); projection.registerCallback(cb, handler); return (START_NOT_STICKY); }
From source file:com.commonsware.android.andcorder.RecorderService.java
@Override public int onStartCommand(Intent i, int flags, int startId) { if (i.getAction() == null) { resultCode = i.getIntExtra(EXTRA_RESULT_CODE, 1337); resultData = i.getParcelableExtra(EXTRA_RESULT_INTENT); if (recordOnNextStart) { startRecorder();/*from www . j ava 2 s . c o m*/ } foregroundify(!recordOnNextStart); recordOnNextStart = false; } else if (ACTION_RECORD.equals(i.getAction())) { if (resultData != null) { foregroundify(false); startRecorder(); } else { Intent ui = new Intent(this, MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(ui); recordOnNextStart = true; } } else if (ACTION_STOP.equals(i.getAction())) { foregroundify(true); stopRecorder(); } else if (ACTION_SHUTDOWN.equals(i.getAction())) { stopSelf(); } return (START_NOT_STICKY); }