Example usage for android.content Intent getParcelableArrayExtra

List of usage examples for android.content Intent getParcelableArrayExtra

Introduction

In this page you can find the example usage for android.content Intent getParcelableArrayExtra.

Prototype

public Parcelable[] getParcelableArrayExtra(String name) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:net.eledge.android.europeana.gui.activity.RecordActivity.java

private void handleIntent(Intent intent) {
    String id = null;//from   w  w w. j ava2s.  co  m
    if (intent != null) {
        if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) {
            Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
            // only one message sent during the beam
            NdefMessage msg = (NdefMessage) rawMsgs[0];
            // record 0 contains the MIME type, record 1 is the AAR, if present
            id = new String(msg.getRecords()[0].getPayload());
        } else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
            id = StringUtils.defaultIfBlank(intent.getDataString(), intent.getStringExtra(RECORD_ID));
        }
        if (StringUtils.contains(id, "europeana.eu/")) {
            Uri uri = Uri.parse(id);
            List<String> paths = uri.getPathSegments();
            if ((paths != null) && (paths.size() == 4)) {
                String collectionId = paths.get(paths.size() - 2);
                String recordId = StringUtils.removeEnd(paths.get(paths.size() - 1), ".html");
                id = StringUtils.join("/", collectionId, "/", recordId);
            } else {
                // invalid url/id, cancel opening record
                id = null;
            }
        }
        if (StringUtils.isNotBlank(id)) {
            openRecord(id);
        }
    }
}

From source file:com.bonsai.wallet32.PairWalletActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    mRes = getApplicationContext().getResources();
    mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pair_wallet);

    // Set the state of the reduce false positives checkbox.
    boolean reduceFalsePositives = mPrefs.getBoolean("pref_reduceBloomFalsePositives", false);
    CheckBox chkbx = (CheckBox) findViewById(R.id.reduce_false_positives);
    chkbx.setChecked(reduceFalsePositives);
    chkbx.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override//from  w ww .ja  v a2  s .c om
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SharedPreferences.Editor editor = mPrefs.edit();
            editor.putBoolean("pref_reduceBloomFalsePositives", isChecked);
            editor.commit();
        }
    });

    // Hide the reduce bloom false positives if experimental off.
    Boolean isExperimental = mPrefs.getBoolean(SettingsActivity.KEY_EXPERIMENTAL, false);
    if (!isExperimental) {
        findViewById(R.id.reduce_false_positives).setVisibility(View.GONE);
        findViewById(R.id.reduce_space).setVisibility(View.GONE);
    }

    if (savedInstanceState == null) {
        final Intent intent = this.getIntent();
        final String action = intent.getAction();
        final String mimeType = intent.getType();

        if ((NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action))
                && Nfc.MIMETYPE_WALLET32PAIRING.equals(mimeType)) {
            final NdefMessage ndefMessage = (NdefMessage) intent
                    .getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)[0];
            final byte[] ndefMessagePayload = Nfc.extractMimePayload(Nfc.MIMETYPE_WALLET32PAIRING, ndefMessage);
            JSONObject codeObj;

            try {
                String msg = new String(ndefMessagePayload, "UTF-8");
                codeObj = new JSONObject(msg);
            } catch (Exception ex) {
                String msg = "trouble deserializing pairing code: " + ex.toString() + " : "
                        + ndefMessagePayload.toString();
                mLogger.error(msg);
                Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
                return;
            }

            // Setup the wallet in a background task.
            new PairWalletTask().execute(codeObj);
        }
    }
}

From source file:org.mozilla.gecko.overlays.ui.ShareDialog.java

/**
 * Called when a UI event broadcast is received from the SendTab ShareMethod.
 *//*ww  w .  jav  a  2s.co  m*/
protected void handleSendTabUIEvent(Intent intent) {
    sendTabOverrideIntent = intent.getParcelableExtra(SendTab.OVERRIDE_INTENT);

    RemoteClient[] remoteClientRecords = (RemoteClient[]) intent
            .getParcelableArrayExtra(SendTab.EXTRA_REMOTE_CLIENT_RECORDS);

    // Escape hatch: we don't show the option to open this dialog in this state so this should
    // never be run. However, due to potential inconsistencies in synced client state
    // (e.g. bug 1122302 comment 47), we might fail.
    if (state == State.DEVICES_ONLY && (remoteClientRecords == null || remoteClientRecords.length == 0)) {
        Log.e(LOGTAG, "In state: " + State.DEVICES_ONLY + " and received 0 synced clients. Finishing...");
        Toast.makeText(this, getResources().getText(R.string.overlay_no_synced_devices), Toast.LENGTH_SHORT)
                .show();
        finish();
        return;
    }

    sendTabList.setSyncClients(remoteClientRecords);

    if (state == State.DEVICES_ONLY || remoteClientRecords == null
            || remoteClientRecords.length <= MAXIMUM_INLINE_DEVICES) {
        // Show the list of devices in-line.
        sendTabList.switchState(SendTabList.State.LIST);

        // The first item in the list has a unique style. If there are no items
        // in the list, the next button appears to be the first item in the list.
        //
        // Note: a more thorough implementation would add this
        // (and other non-ListView buttons) into a custom ListView.
        if (remoteClientRecords == null || remoteClientRecords.length == 0) {
            readingListButton.setBackgroundResource(R.drawable.overlay_share_button_background_first);
        }
        return;
    }

    // Just show a button to launch the list of devices to choose from.
    sendTabList.switchState(SendTabList.State.SHOW_DEVICES);
}

From source file:com.piusvelte.taplock.client.core.TapLockToggle.java

@Override
public void onServiceConnected(ComponentName name, IBinder binder) {
    mServiceInterface = ITapLockService.Stub.asInterface(binder);
    if (mUIInterface != null) {
        try {/*from   w w  w  .  j a v a 2  s  .com*/
            mServiceInterface.setCallback(mUIInterface);
        } catch (RemoteException e) {
            Log.e(TAG, e.toString());
        }
    }
    Intent intent = getIntent();
    if (intent != null) {
        String action = intent.getAction();
        if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)
                && intent.hasExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)) {
            Log.d(TAG, "service connected, NDEF_DISCOVERED");
            Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
            NdefMessage message;
            if (rawMsgs != null) {
                // process the first message
                message = (NdefMessage) rawMsgs[0];
                // process the first record
                NdefRecord record = message.getRecords()[0];
                if (record.getTnf() == NdefRecord.TNF_WELL_KNOWN) {
                    try {
                        byte[] payload = record.getPayload();
                        /*
                         * payload[0] contains the "Status Byte Encodings" field, per the
                         * NFC Forum "Text Record Type Definition" section 3.2.1.
                         *
                         * bit7 is the Text Encoding Field.
                         *
                         * if (Bit_7 == 0): The text is encoded in UTF-8 if (Bit_7 == 1):
                         * The text is encoded in UTF16
                         *
                         * Bit_6 is reserved for future use and must be set to zero.
                         *
                         * Bits 5 to 0 are the length of the IANA language code.
                         */
                        String textEncoding = ((payload[0] & 0200) == 0) ? "UTF-8" : "UTF-16";
                        int languageCodeLength = payload[0] & 0077;
                        String taggedDeviceName = new String(payload, languageCodeLength + 1,
                                payload.length - languageCodeLength - 1, textEncoding);
                        manageDevice(taggedDeviceName, ACTION_TOGGLE);
                    } catch (UnsupportedEncodingException e) {
                        // should never happen unless we get a malformed tag.
                        Log.e(TAG, e.toString());
                        finish();
                    }
                } else
                    finish();
            } else
                finish();
        } else if (intent.getData() != null) {
            String taggedDeviceName = intent.getData().getHost();
            if (taggedDeviceName != null)
                manageDevice(taggedDeviceName, ACTION_TOGGLE);
            else
                finish();
        } else if (ACTION_UNLOCK.equals(action) || ACTION_LOCK.equals(action) || ACTION_TOGGLE.equals(action))
            manageDevice(intent.getStringExtra(EXTRA_DEVICE_NAME), action);
        else
            finish();
    } else
        finish();
}

From source file:se.anyro.nfc_reader.TagViewer.java

private void resolveIntent(Intent intent) {
    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;// www .  ja v a  2  s. c  o m
        if (rawMsgs != null) {
            msgs = new NdefMessage[rawMsgs.length];
            for (int i = 0; i < rawMsgs.length; i++) {
                msgs[i] = (NdefMessage) rawMsgs[i];

                // magic happens here
                processReadTag((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 };
        }
        // Setup the views
        buildTagViews(msgs);
    }
}

From source file:com.os.mobile.blinkid.BlinkIdPlugin.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);

    if (requestCode == MY_PHOTOPAY_REQUEST_CODE) {

        // make sure PhotoPay activity returned result
        if (resultCode == ScanActivity.RESULT_OK && intent != null) {

            // depending on settings, we may have multiple scan results.
            // we first need to obtain list of recognition results
            Parcelable[] multiData = intent
                    .getParcelableArrayExtra(ScanActivity.EXTRAS_RECOGNITION_RESULT_LIST);

            if (multiData != null) {

                Log.i(this, "Data count: " + multiData.length);
                int i = 1;

                for (Parcelable parc : multiData) {
                    Log.i(this, "Data #" + Integer.valueOf(i++).toString());

                    // each element in multiData is actually class derived from BaseRecognitionResult
                    // so it is always safe to cast
                    // Moreover, as is specified in README file, you can use instanceof operator
                    // to determine the actual type of result. Here we will simply pass
                    // the result list to ResultActivity and there we will explain
                    // how to retrieve data from result.

                    BaseRecognitionResult rd = (BaseRecognitionResult) parc;

                    /* Create JSON to send as a result to the call of the Plugin  */
                    if (rd != null) {
                        JSONObject jsonObject = new JSONObject();
                        try {
                            jsonObject.put("isParsed", ((MRTDRecognitionResult) rd).isMRZParsed());
                            jsonObject.put("issuer", ((MRTDRecognitionResult) rd).getIssuer());
                            jsonObject.put("documentNumber", ((MRTDRecognitionResult) rd).getDocumentNumber());
                            jsonObject.put("documentCode", ((MRTDRecognitionResult) rd).getDocumentCode());
                            jsonObject.put("dateOfExpiry", ((MRTDRecognitionResult) rd).getDateOfExpiry());
                            jsonObject.put("primaryId", ((MRTDRecognitionResult) rd).getPrimaryId());
                            jsonObject.put("secondaryId", ((MRTDRecognitionResult) rd).getSecondaryId());
                            jsonObject.put("dateOfBirth", ((MRTDRecognitionResult) rd).getDateOfBirth());
                            jsonObject.put("nationality", ((MRTDRecognitionResult) rd).getNationality());
                            jsonObject.put("sex", ((MRTDRecognitionResult) rd).getSex());
                            jsonObject.put("opt1", ((MRTDRecognitionResult) rd).getOpt1());
                            jsonObject.put("opt2", ((MRTDRecognitionResult) rd).getOpt2());
                            jsonObject.put("mrzText", ((MRTDRecognitionResult) rd).getMRZText());

                            this.callbackContext.success(jsonObject.toString());
                            // break;
                        } catch (JSONException e) {
                            Log.e("MicroBlink", e.toString());
                        }//  www .  j a v a2 s  .co m
                    }

                }
            } else {
                Log.e(this, "Unable to retrieve list of recognition data!");
            }

            // set intent's component to ResultActivity and pass its contents
            // to ResultActivity. ResultActivity will show how to extract
            // data from result.

            //   intent.setComponent(new ComponentName(this, ResultActivity.class));
            //   startActivity(intent);
        } else {
            // if PhotoPay activity did not return result, user has probably
            // pressed Back button and cancelled scanning
            Toast.makeText(cordova.getActivity(), "Scan cancelled!", Toast.LENGTH_SHORT).show();
        }
    }
}

From source file:mai.whack.StickyNotesActivity.java

private void onDataRead(Intent intent) {
    // Parse the intent
    NdefMessage[] msgs = null;/*from   w  w  w .  j ava2  s .co m*/
    String action = intent.getAction();
    byte[] tagId = null;
    if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(action) || NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) {
        Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
        tagId = intent.getByteArrayExtra(NfcAdapter.EXTRA_ID);
        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.d(TAG, "Unknown intent.");
        finish();
    }

    String msg = new String(msgs[0].getRecords()[0].getPayload());
    mHttpGetThread = new HttpGetThread("http://192.168.1.192/store/" + toHex(tagId));
    mHttpGetThread.start();
    // mHttpPostThread = new HttpPostThread("aaaaa", "bbbbb", "sdgsdfdsfs");
    // mHttpPostThread.start();
}

From source file:com.example.mynsocial.BluetoothChat.java

NdefMessage[] getNdefMessages(Intent intent) {
    Log.e(TAG, "+++ getNdefMessages +++");
    NdefMessage[] msgs = null;//from   ww w .j  a v a2  s.  co  m
    if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(intent.getAction())) {
        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 {
            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.d("Peer to Peer 2", "Unknown intent.");
        finish();
    }

    return msgs;
}

From source file:net.networksaremadeofstring.rhybudd.PushSettingsFragment.java

void processIntent(Intent intent) {
    //Log.e("processIntent","processIntent");
    try {//from w  ww  .ja v a 2 s .  c  o m
        Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
        // only one message sent during the beam
        NdefMessage msg = (NdefMessage) rawMsgs[0];

        //Backup our current key
        prevFilterKey = FilterKey.getText().toString();

        // record 0 contains the MIME type, record 1 is the AAR, if present
        FilterKey.setText(new String(msg.getRecords()[0].getPayload()));

        /*Message message = Message.obtain();
        Bundle bundle = new Bundle();
        bundle.putString("newfilterkey",new String(msg.getRecords()[0].getPayload()));
        message.setData(bundle);
        message.what = RhybuddHandlers.msg_push_show_undo;
        checkZPHandler.sendMessageDelayed(message,600);*/

    } catch (Exception e) {
        e.printStackTrace();
        BugSenseHandler.sendExceptionMessage("PushSettingsFragment", "processIntent", e);
    }
}

From source file:org.getlantern.firetweet.activity.support.MediaViewerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mActionBar = getSupportActionBar();/* ww  w  .ja v a2s .c o m*/
    mActionBar.setDisplayHomeAsUpEnabled(true);
    setContentView(R.layout.activity_media_viewer);
    mAdapter = new MediaPagerAdapter(this);
    mViewPager.setAdapter(mAdapter);
    mViewPager.setPageMargin(getResources().getDimensionPixelSize(R.dimen.element_spacing_normal));
    mViewPager.setOnPageChangeListener(this);
    final Intent intent = getIntent();
    final long accountId = intent.getLongExtra(EXTRA_ACCOUNT_ID, -1);
    final ParcelableMedia[] media = Utils.newParcelableArray(intent.getParcelableArrayExtra(EXTRA_MEDIA),
            ParcelableMedia.CREATOR);
    final ParcelableMedia currentMedia = intent.getParcelableExtra(EXTRA_CURRENT_MEDIA);
    mAdapter.setMedia(accountId, media);
    final int currentIndex = ArrayUtils.indexOf(media, currentMedia);
    if (currentIndex != -1) {
        mViewPager.setCurrentItem(currentIndex, false);
    }
    if (intent.hasExtra(EXTRA_STATUS)) {
        mMediaStatusContainer.setVisibility(View.VISIBLE);
        final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        final Fragment f = new ViewStatusDialogFragment();
        final Bundle args = new Bundle();
        args.putParcelable(EXTRA_STATUS, intent.getParcelableExtra(EXTRA_STATUS));
        args.putBoolean(EXTRA_SHOW_MEDIA_PREVIEW, false);
        args.putBoolean(EXTRA_SHOW_EXTRA_TYPE, false);
        f.setArguments(args);
        ft.replace(R.id.media_status, f);
        ft.commit();
    } else {
        mMediaStatusContainer.setVisibility(View.GONE);
    }
}