List of usage examples for android.content Intent getByteArrayExtra
public byte[] getByteArrayExtra(String name)
From source file:com.nutomic.syncthingandroid.util.BarcodeIntentIntegrator.java
/** * <p>Call this from your {@link Activity}'s * {@link Activity#onActivityResult(int, int, Intent)} method.</p> * * @param requestCode request code from {@code onActivityResult()} * @param resultCode result code from {@code onActivityResult()} * @param intent {@link Intent} from {@code onActivityResult()} * @return null if the event handled here was not related to this class, or * else an {@link BarcodeIntentResult} containing the result of the scan. If the user cancelled scanning, * the fields will be null.//from ww w .j a v a 2 s . c om */ public static BarcodeIntentResult parseActivityResult(int requestCode, int resultCode, Intent intent) { if (requestCode == REQUEST_CODE) { if (resultCode == Activity.RESULT_OK) { String contents = intent.getStringExtra("SCAN_RESULT"); String formatName = intent.getStringExtra("SCAN_RESULT_FORMAT"); byte[] rawBytes = intent.getByteArrayExtra("SCAN_RESULT_BYTES"); int intentOrientation = intent.getIntExtra("SCAN_RESULT_ORIENTATION", Integer.MIN_VALUE); Integer orientation = intentOrientation == Integer.MIN_VALUE ? null : intentOrientation; String errorCorrectionLevel = intent.getStringExtra("SCAN_RESULT_ERROR_CORRECTION_LEVEL"); return new BarcodeIntentResult(contents, formatName, rawBytes, orientation, errorCorrectionLevel); } return new BarcodeIntentResult(); } return null; }
From source file:com.philliphsu.clock2.alarms.background.UpcomingAlarmReceiver.java
@Override public void onReceive(final Context context, final Intent intent) { final byte[] alarmBytes = intent.getByteArrayExtra(EXTRA_ALARM); // Unmarshall the bytes into a parcel and create our Alarm with it. final Alarm alarm = ParcelableUtil.unmarshall(alarmBytes, Alarm.CREATOR); if (alarm == null) { throw new IllegalStateException("No alarm received"); }/*from ww w. j a v a 2 s . c om*/ final long id = alarm.getId(); final NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); final boolean actionShowSnoozing = ACTION_SHOW_SNOOZING.equals(intent.getAction()); if (intent.getAction() == null || actionShowSnoozing) { // Prepare notification // http://stackoverflow.com/a/15803726/5055032 // Notifications aren't updated on the UI thread, so we could have // done this in the background. However, no lengthy operations are // done here, so doing so is a premature optimization. String title; String text; if (actionShowSnoozing) { if (!alarm.isSnoozed()) { throw new IllegalStateException("Can't show snoozing notif. if alarm not snoozed!"); } title = alarm.label().isEmpty() ? context.getString(R.string.alarm) : alarm.label(); text = context.getString(R.string.title_snoozing_until, formatTime(context, alarm.snoozingUntil())); } else { // No intent action required for default behavior title = context.getString(R.string.upcoming_alarm); text = formatTime(context, alarm.ringsAt()); if (!alarm.label().isEmpty()) { text = alarm.label() + ", " + text; } } Intent dismissIntent = new Intent(context, UpcomingAlarmReceiver.class).setAction(ACTION_DISMISS_NOW) .putExtra(EXTRA_ALARM, ParcelableUtil.marshall(alarm)); PendingIntent piDismiss = PendingIntent.getBroadcast(context, (int) id, dismissIntent, PendingIntent.FLAG_CANCEL_CURRENT); Notification note = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.ic_alarm_24dp) .setContentTitle(title).setContentText(text) .setContentIntent(ContentIntentUtils.create(context, MainActivity.PAGE_ALARMS, id)) .addAction(R.drawable.ic_dismiss_alarm_24dp, context.getString(R.string.dismiss_now), piDismiss) .build(); nm.notify(TAG, (int) id, note); } else if (ACTION_CANCEL_NOTIFICATION.equals(intent.getAction())) { nm.cancel(TAG, (int) id); } else if (ACTION_DISMISS_NOW.equals(intent.getAction())) { new AlarmController(context, null).cancelAlarm(alarm, false, true); } }
From source file:com.finchuk.clock2.alarms.background.UpcomingAlarmReceiver.java
@Override public void onReceive(final Context context, final Intent intent) { final byte[] alarmBytes = intent.getByteArrayExtra(EXTRA_ALARM); // Unmarshall the bytes into a parcel and create our Alarm with it. final Alarm alarm = ParcelableUtil.unmarshall(alarmBytes, Alarm.CREATOR); if (alarm == null) { throw new IllegalStateException("No alarm received"); }//from w ww. j a v a 2s.c om final long id = alarm.getId(); final NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); final boolean actionShowSnoozing = ACTION_SHOW_SNOOZING.equals(intent.getAction()); if (intent.getAction() == null || actionShowSnoozing) { // Prepare notification // http://stackoverflow.com/a/15803726/5055032 // Notifications aren't updated on the UI thread, so we could have // done this in the background. However, no lengthy operations are // done here, so doing so is a premature optimization. String title; String text; if (actionShowSnoozing) { if (!alarm.isSnoozed()) { throw new IllegalStateException("Can't show snoozing notif. if alarm not snoozed!"); } title = alarm.label().isEmpty() ? context.getString(R.string.alarm) : alarm.label(); text = context.getString(R.string.title_snoozing_until, TimeFormatUtils.formatTime(context, alarm.snoozingUntil())); } else { // No intent action required for default behavior title = context.getString(R.string.upcoming_alarm); text = TimeFormatUtils.formatTime(context, alarm.ringsAt()); if (!alarm.label().isEmpty()) { text = alarm.label() + ", " + text; } } Intent dismissIntent = new Intent(context, UpcomingAlarmReceiver.class).setAction(ACTION_DISMISS_NOW) .putExtra(EXTRA_ALARM, ParcelableUtil.marshall(alarm)); PendingIntent piDismiss = PendingIntent.getBroadcast(context, (int) id, dismissIntent, PendingIntent.FLAG_CANCEL_CURRENT); Notification note = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.ic_alarm_24dp) .setContentTitle(title).setContentText(text) .setContentIntent(ContentIntentUtils.create(context, MainActivity.PAGE_ALARMS, id)) .addAction(R.drawable.ic_dismiss_alarm_24dp, context.getString(R.string.dismiss_now), piDismiss) .build(); nm.notify(TAG, (int) id, note); } else if (ACTION_CANCEL_NOTIFICATION.equals(intent.getAction())) { nm.cancel(TAG, (int) id); } else if (ACTION_DISMISS_NOW.equals(intent.getAction())) { new AlarmController(context, null).cancelAlarm(alarm, false, true); } }
From source file:org.schabi.terminightor.NightKillerActivity.java
@Override public void onNewIntent(Intent intent) { super.onNewIntent(intent); byte[] nfcId = intent.getByteArrayExtra(NfcAdapter.EXTRA_ID); if (nfcId != null) { if (Arrays.equals(nfcId, expectedNfcId) || ignoreNfcTagId) { Log.d(TAG, "Send kill alarm"); Intent killAlarmIntent = new Intent(NightKillerService.ACTION_KILL_ALARM); LocalBroadcastManager.getInstance(this).sendBroadcast(killAlarmIntent); finish();//from ww w .ja v a 2 s.com } else { Toast.makeText(this, R.string.wrongTagToast, Toast.LENGTH_SHORT).show(); Log.d(TAG, "Expected: " + Arrays.toString(expectedNfcId)); Log.d(TAG, "Given: " + Arrays.toString(nfcId)); } } }
From source file:com.anjalimacwan.receiver.WearPluginReceiver.java
@Override public void onReceive(Context context, Intent intent) { try {//from w w w . j a v a 2s . c o m // Write note to disk FileOutputStream output = context.openFileOutput(String.valueOf(System.currentTimeMillis()), Context.MODE_PRIVATE); output.write(intent.getByteArrayExtra("note")); output.close(); } catch (IOException e) { /* Gracefully fail */ } // Send broadcast to NoteListFragment to refresh list of notes Intent listNotesIntent = new Intent(); listNotesIntent.setAction("com.anjalimacwan.LIST_NOTES"); LocalBroadcastManager.getInstance(context).sendBroadcast(listNotesIntent); }
From source file:com.notepadlite.WearPluginReceiver.java
@Override public void onReceive(Context context, Intent intent) { try {/*from w w w . j ava2s. co m*/ // Write note to disk FileOutputStream output = context.openFileOutput(String.valueOf(System.currentTimeMillis()), Context.MODE_PRIVATE); output.write(intent.getByteArrayExtra("note")); output.close(); } catch (IOException e) { } // Send broadcast to NoteListFragment to refresh list of notes Intent listNotesIntent = new Intent(); listNotesIntent.setAction("com.notepadlite.LIST_NOTES"); LocalBroadcastManager.getInstance(context).sendBroadcast(listNotesIntent); }
From source file:de.petendi.ethereum.android.EthereumAndroid.java
private void handleResponse(Intent reponse) { int id = reponse.getIntExtra(ID, 0); String error = reponse.getStringExtra(EXTRA_ERROR); byte[] response = reponse.getByteArrayExtra(EXTRA_DATA); if (error != null) { try {//from w w w . j a va 2s. co m ServiceError errorObj = objectMapper.readValue(error, ServiceError.class); callback.handleError(id, errorObj); } catch (IOException e) { throw new IllegalArgumentException(e); } } else if (response != null) { try { WrappedResponse responseObj = objectMapper.readValue(response, WrappedResponse.class); callback.handleResponse(id, responseObj); } catch (IOException e) { throw new IllegalArgumentException(e); } } }
From source file:com.finchuk.clock2.timers.TimerNotificationService.java
@Override protected void handleDefaultAction(Intent intent, int flags, int startId) { final byte[] bytes = intent.getByteArrayExtra(EXTRA_TIMER); if (bytes == null) { throw new IllegalStateException("Cannot start TimerNotificationService without a Timer"); }//from www. j a v a2 s . co m final Timer timer = ParcelableUtil.unmarshall(bytes, Timer.CREATOR); final long id = timer.getId(); boolean updateChronometer = false; Timer oldTimer = mTimers.put(id, timer); if (oldTimer != null) { updateChronometer = oldTimer.endTime() != timer.endTime(); } mControllers.put(id, new TimerController(timer, mUpdateHandler)); mMostRecentTimerId = id; // If isUpdate == true, this won't call through because the id already exists in the // internal mappings as well. registerNewNoteBuilder(id); // The note's title should change here every time, especially if the Timer's label was updated. String title = timer.label(); if (title.isEmpty()) { title = getString(com.finchuk.clock2.R.string.timer); } setContentTitle(id, title); if (updateChronometer) { // Immediately push any duration updates, or else there will be a noticeable delay. setBase(id, timer.endTime()); updateNotification(id, true); } // This handles any other notification updates like the title or actions, even if // the timer is not running because the current thread will update the notification // (besides the content text) before quitting. syncNotificationWithTimerState(id, timer.isRunning()); }
From source file:com.philliphsu.clock2.timers.TimerNotificationService.java
@Override protected void handleDefaultAction(Intent intent, int flags, int startId) { final byte[] bytes = intent.getByteArrayExtra(EXTRA_TIMER); if (bytes == null) { throw new IllegalStateException("Cannot start TimerNotificationService without a Timer"); }/* ww w . j a v a 2s.c o m*/ final Timer timer = ParcelableUtil.unmarshall(bytes, Timer.CREATOR); final long id = timer.getId(); boolean updateChronometer = false; Timer oldTimer = mTimers.put(id, timer); if (oldTimer != null) { updateChronometer = oldTimer.endTime() != timer.endTime(); } mControllers.put(id, new TimerController(timer, mUpdateHandler)); mMostRecentTimerId = id; // If isUpdate == true, this won't call through because the id already exists in the // internal mappings as well. registerNewNoteBuilder(id); // The note's title should change here every time, especially if the Timer's label was updated. String title = timer.label(); if (title.isEmpty()) { title = getString(R.string.timer); } setContentTitle(id, title); if (updateChronometer) { // Immediately push any duration updates, or else there will be a noticeable delay. setBase(id, timer.endTime()); updateNotification(id, true); } // This handles any other notification updates like the title or actions, even if // the timer is not running because the current thread will update the notification // (besides the content text) before quitting. syncNotificationWithTimerState(id, timer.isRunning()); }
From source file:org.sufficientlysecure.keychain.remote.ui.RemoteRegisterActivity.java
@Override protected void onStart() { super.onStart(); Intent intent = getIntent(); Intent resultData = intent.getParcelableExtra(EXTRA_DATA); String packageName = intent.getStringExtra(EXTRA_PACKAGE_NAME); byte[] packageSignature = intent.getByteArrayExtra(EXTRA_PACKAGE_SIGNATURE); presenter.setupFromIntentData(resultData, packageName, packageSignature); }