List of usage examples for android.content Intent getParcelableArrayExtra
public Parcelable[] getParcelableArrayExtra(String name)
From source file:com.phonegap.plugins.pdf417.Pdf417Scanner.java
/** * Called when the scanner intent completes. * /*from w ww .ja v a2 s . c om*/ * @param requestCode * The request code originally supplied to * startActivityForResult(), allowing you to identify who this * result came from. * @param resultCode * The integer result code returned by the child activity through * its setResult(). * @param intent * An Intent, which can return result data to the caller (various * data can be attached to Intent "extras"). */ @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_CODE) { if (resultCode == Pdf417ScanActivity.RESULT_OK) { // First, obtain 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. Parcelable[] resultArray = data .getParcelableArrayExtra(Pdf417ScanActivity.EXTRAS_RECOGNITION_RESULT_LIST); // 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. JSONArray resultsList = new JSONArray(); for (Parcelable p : resultArray) { try { if (p instanceof Pdf417ScanResult) { // check if scan result is result of Pdf417 recognizer resultsList.put(parsePdf417((Pdf417ScanResult) p)); } else if (p instanceof BarDecoderScanResult) { // check if scan result is result of BarDecoder recognizer resultsList.put(parseBarDecoder((BarDecoderScanResult) p)); } else if (p instanceof ZXingScanResult) { // check if scan result is result of ZXing recognizer resultsList.put(parseZxing((ZXingScanResult) p)); } else if (p instanceof USDLScanResult) { // check if scan result is result of US Driver's Licence recognizer resultsList.put(parseUSDL((USDLScanResult) p)); } } catch (Exception e) { Log.e(LOG_TAG, "Error parsing " + p.getClass().getName()); } } try { JSONObject root = new JSONObject(); root.put(RESULT_LIST, resultsList); root.put(CANCELLED, false); this.callbackContext.success(root); } catch (JSONException e) { Log.e(LOG_TAG, "This should never happen"); } } else if (resultCode == Pdf417ScanActivity.RESULT_CANCELED) { JSONObject obj = new JSONObject(); try { obj.put(CANCELLED, true); } catch (JSONException e) { Log.e(LOG_TAG, "This should never happen"); } this.callbackContext.success(obj); } else { this.callbackContext.error("Unexpected error"); } } }
From source file:net.lp.hivawareness.v4.HIVAwarenessActivity.java
/** * Parses the NDEF Message from the intent and prints to the TextView *//*from w w w .ja va 2 s .co m*/ void processIntent(Intent intent) { Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); // only one message sent during the beam NdefMessage msg = (NdefMessage) rawMsgs[0]; String data = new String(msg.getRecords()[0].getPayload()); String[] parts = data.split("\\|"); // record 0 contains the MIME type, record 1 is the AAR, if present Log.v("HIV", "old status " + caught + " " + data); double partnerInfected = Double.parseDouble(parts[0]); Gender partnerGender = Gender.valueOf(parts[1]); updateInfectionStatus(partnerInfected, partnerGender); if (!HIVAwarenessActivity.DEBUG) FlurryAgent.onEvent("touched"); AnalyticsUtils.getInstance().trackGAEvent("HIVAwarenessActivity", "Touched", this.getLocalClassName() + ".ListClick", caught); Log.v("HIV", "new status " + caught); showDialog(SMOKING_DIALOG_ID); }
From source file:org.ounl.lifelonglearninghub.mediaplayer.cast.refplayer.NFCVideoBrowserActivity.java
/** * On create, process NDEF message with its intent action * /* ww w . ja va 2s .c o m*/ * @param intent */ private String resolveIntent(Intent intent) { Log.d(CLASSNAME, "resolveIntent is called intent:" + intent.toString()); String action = intent.getAction(); if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(action) || NfcAdapter.ACTION_TECH_DISCOVERED.equals(action) || NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) { Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); NdefMessage[] msgs; if (rawMsgs != null) { msgs = new NdefMessage[rawMsgs.length]; for (int i = 0; i < rawMsgs.length; i++) { msgs[i] = (NdefMessage) rawMsgs[i]; } } else { // Unknown tag type byte[] empty = new byte[0]; byte[] id = intent.getByteArrayExtra(NfcAdapter.EXTRA_ID); Parcelable tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); byte[] payload = dumpTagData(tag).getBytes(); NdefRecord record = new NdefRecord(NdefRecord.TNF_UNKNOWN, empty, id, payload); NdefMessage msg = new NdefMessage(new NdefRecord[] { record }); msgs = new NdefMessage[] { msg }; } return processNdefMessageArray(msgs); } return IParsedNdefCommand.COMMAND_UNKNOWN; }
From source file:net.eledge.android.europeana.gui.activity.SearchActivity.java
private void handleIntent(Intent intent) { String query = null;/*from w w w .j a v a2 s. c o m*/ String[] qf = null; if (intent != null) { if (Intent.ACTION_SEARCH.equals(intent.getAction())) { query = intent.getStringExtra(SearchManager.QUERY); qf = splitFacets(intent.getStringExtra(SearchManager.USER_QUERY)); } else if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) { Parcelable[] parcelables = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); NdefMessage msg = (NdefMessage) parcelables[0]; Uri uri = Uri.parse(new String(msg.getRecords()[0].getPayload())); query = uri.getQueryParameter("query"); qf = StringArrayUtils.toArray(uri.getQueryParameters("qf")); } else if (Intent.ACTION_VIEW.equals(intent.getAction())) { query = intent.getDataString(); if (!TextUtils.isEmpty(query)) { if (StringUtils.contains(query, "europeana.eu/")) { Uri uri = Uri.parse(query); query = uri.getQueryParameter("query"); qf = StringArrayUtils.toArray(uri.getQueryParameters("qf")); } } } else { // no search action recognized? end this activity... closeSearchActivity(); } if (!TextUtils.isEmpty(query) && !TextUtils.equals(runningSearch, query)) { runningSearch = query; if (StringArrayUtils.isNotBlank(qf)) { searchController.newSearch(this, query, qf); } else { searchController.newSearch(this, query); } getSupportActionBar().setTitle(searchController.getSearchTitle(this)); } } }
From source file:com.googlecode.android_scripting.facade.ui.NFCBeamTask.java
@SuppressLint("NewApi") NdefMessage[] getNdefMessagesFromIntent(Intent intent) { // Parse the intent NdefMessage[] msgs = null;//from w w w . j a v a 2 s .co m String action = intent.getAction(); if (action.equals(NfcAdapter.ACTION_TAG_DISCOVERED) || action.equals(NfcAdapter.ACTION_NDEF_DISCOVERED)) { Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); if (rawMsgs != null) { msgs = new NdefMessage[rawMsgs.length]; for (int i = 0; i < rawMsgs.length; i++) { msgs[i] = (NdefMessage) rawMsgs[i]; } } else { // Unknown tag type byte[] empty = new byte[] {}; NdefRecord record = new NdefRecord(NdefRecord.TNF_UNKNOWN, empty, empty, empty); NdefMessage msg = new NdefMessage(new NdefRecord[] { record }); msgs = new NdefMessage[] { msg }; } } else { Log.e(TAG, "Unknown intent."); finish(); } return msgs; }
From source file:com.github.michalbednarski.intentslab.ReceiveBroadcastService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { // Flag us as running sIsRunning = true;// w w w .j a va2 s. c o m // Prepare receiver and unregister old one if exist if (mReceiver != null) { // We were already started, clear old receiver unregisterReceiver(mReceiver); } else { mReceiver = new MyBroadcastReceiver(); } if (intent.getBooleanExtra("multiple", false)) { sReceivedBroadcasts = new ArrayList<ReceivedBroadcast>(); } else { sReceivedBroadcasts = null; } // Get IntentFilter and register receiver String action = ""; Parcelable[] filters = intent.getParcelableArrayExtra("intentFilters"); if (filters == null || filters.length == 0) { stopSelf(); return START_NOT_STICKY; } for (Parcelable uncastedFilter : filters) { IntentFilter filter = (IntentFilter) uncastedFilter; registerReceiver(mReceiver, filter); if (filters.length == 1) { if (filter.countActions() == 1) { action = filter.getAction(0); } } } // Show notification if (sReceivedBroadcasts != null) { showListeningMultipleNotification(); } else { showWaitingNotification(action); } return START_NOT_STICKY; }
From source file:de.vanita5.twittnuker.service.BackgroundOperationService.java
private void handleUpdateStatusIntent(final Intent intent) { final NotificationCompat.Builder builder = new NotificationCompat.Builder(this); final ParcelableStatusUpdate status = intent.getParcelableExtra(EXTRA_STATUS); final Parcelable[] status_parcelables = intent.getParcelableArrayExtra(EXTRA_STATUSES); final ParcelableStatusUpdate[] statuses; if (status_parcelables != null) { statuses = new ParcelableStatusUpdate[status_parcelables.length]; for (int i = 0, j = status_parcelables.length; i < j; i++) { statuses[i] = (ParcelableStatusUpdate) status_parcelables[i]; }/* w w w. j ava2s. com*/ } else if (status != null) { statuses = new ParcelableStatusUpdate[1]; statuses[0] = status; } else return; startForeground(NOTIFICATION_ID_UPDATE_STATUS, updateUpdateStatusNotification(this, builder, 0, null)); for (final ParcelableStatusUpdate item : statuses) { mNotificationManager.notify(NOTIFICATION_ID_UPDATE_STATUS, updateUpdateStatusNotification(this, builder, 0, item)); final List<SingleResponse<ParcelableStatus>> result = updateStatus(builder, item); boolean failed = false; Exception exception = null; final List<Long> failed_account_ids = ListUtils.fromArray(Account.getAccountIds(item.accounts)); for (final SingleResponse<ParcelableStatus> response : result) { if (response.getData() == null) { failed = true; if (exception == null) { exception = response.getException(); } } else if (response.getData().account_id > 0) { failed_account_ids.remove(response.getData().account_id); } } if (result.isEmpty()) { saveDrafts(item, failed_account_ids, true); showErrorMessage(R.string.action_updating_status, getString(R.string.no_account_selected), false); } else if (failed) { // If the status is a duplicate, there's no need to save it to // drafts. if (exception instanceof TwitterException && ((TwitterException) exception) .getErrorCode() == StatusCodeMessageUtils.STATUS_IS_DUPLICATE) { showErrorMessage(getString(R.string.status_is_duplicate), false); } else if (exception instanceof HototinShortenException) { saveDrafts(item, failed_account_ids, false); } else { saveDrafts(item, failed_account_ids, true); showErrorMessage(R.string.action_updating_status, exception, true); } } else { showOkMessage(R.string.status_updated, false); if (item.medias != null) { for (final ParcelableMediaUpdate media : item.medias) { final String path = getImagePathFromUri(this, Uri.parse(media.uri)); if (path != null) { new File(path).delete(); } } } } if (mPreferences.getBoolean(KEY_REFRESH_AFTER_TWEET, false)) { mTwitter.refreshAll(); } } stopForeground(false); mNotificationManager.cancel(NOTIFICATION_ID_UPDATE_STATUS); }
From source file:org.getlantern.firetweet.service.BackgroundOperationService.java
private void handleUpdateStatusIntent(final Intent intent) { final NotificationCompat.Builder builder = new NotificationCompat.Builder(this); final ParcelableStatusUpdate status = intent.getParcelableExtra(EXTRA_STATUS); final Parcelable[] status_parcelables = intent.getParcelableArrayExtra(EXTRA_STATUSES); final ParcelableStatusUpdate[] statuses; if (status_parcelables != null) { statuses = new ParcelableStatusUpdate[status_parcelables.length]; for (int i = 0, j = status_parcelables.length; i < j; i++) { statuses[i] = (ParcelableStatusUpdate) status_parcelables[i]; }//from w ww . j a va 2s .c o m } else if (status != null) { statuses = new ParcelableStatusUpdate[1]; statuses[0] = status; } else return; startForeground(NOTIFICATION_ID_UPDATE_STATUS, updateUpdateStatusNotificaion(this, builder, 0, null)); for (final ParcelableStatusUpdate item : statuses) { mNotificationManager.notify(NOTIFICATION_ID_UPDATE_STATUS, updateUpdateStatusNotificaion(this, builder, 0, item)); final ContentValues draftValues = ContentValuesCreator.createStatusDraft(item, ParcelableAccount.getAccountIds(item.accounts)); final Uri draftUri = mResolver.insert(Drafts.CONTENT_URI, draftValues); final long draftId = ParseUtils.parseLong(draftUri.getLastPathSegment(), -1); mTwitter.addSendingDraftId(draftId); final List<SingleResponse<ParcelableStatus>> result = updateStatus(builder, item); boolean failed = false; Exception exception = null; final Expression where = Expression.equals(Drafts._ID, draftId); final List<Long> failedAccountIds = ListUtils.fromArray(ParcelableAccount.getAccountIds(item.accounts)); for (final SingleResponse<ParcelableStatus> response : result) { if (response.getData() == null) { failed = true; if (exception == null) { exception = response.getException(); } } else if (response.getData().account_id > 0) { failedAccountIds.remove(response.getData().account_id); } } if (result.isEmpty()) { showErrorMessage(R.string.action_updating_status, getString(R.string.no_account_selected), false); } else if (failed) { // If the status is a duplicate, there's no need to save it to // drafts. if (exception instanceof TwitterException && ((TwitterException) exception) .getErrorCode() == StatusCodeMessageUtils.STATUS_IS_DUPLICATE) { showErrorMessage(getString(R.string.status_is_duplicate), false); } else { final ContentValues accountIdsValues = new ContentValues(); accountIdsValues.put(Drafts.ACCOUNT_IDS, ListUtils.toString(failedAccountIds, ',', false)); mResolver.update(Drafts.CONTENT_URI, accountIdsValues, where.getSQL(), null); showErrorMessage(R.string.action_updating_status, exception, true); displayTweetNotSendNotification(); } } else { showOkMessage(R.string.status_updated, false); mResolver.delete(Drafts.CONTENT_URI, where.getSQL(), null); if (item.media != null) { for (final ParcelableMediaUpdate media : item.media) { final String path = getImagePathFromUri(this, Uri.parse(media.uri)); if (path != null) { if (!new File(path).delete()) { Log.d(LOGTAG, String.format("unable to delete %s", path)); } } } } } mTwitter.removeSendingDraftId(draftId); if (mPreferences.getBoolean(KEY_REFRESH_AFTER_TWEET, false)) { mHandler.post(new Runnable() { @Override public void run() { mTwitter.refreshAll(); } }); } } stopForeground(false); mNotificationManager.cancel(NOTIFICATION_ID_UPDATE_STATUS); }
From source file:us.rader.wyfy.MainActivity.java
/** * Parse the data passed in the given <code>Intent</code> at launch * /* ww w . j av a2 s .c om*/ * @return <code>true</code> if and only if an asynchronouse attempt to * connect was launched */ private boolean parseIntentData() { Intent intent = getIntent(); if (intent == null) { return false; } Uri uri = intent.getData(); if (uri != null) { return parseUri(uri.toString()); } Parcelable[] ndefMessages = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); if ((ndefMessages != null) && (ndefMessages.length > 0)) { return parseLegacyMessage((NdefMessage) ndefMessages[0]); } return false; }