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:org.sufficientlysecure.keychain.ui.ImportKeysProxyActivity.java

/**
 * NFC: Parses the NDEF Message from the intent and prints to the TextView
 *///from w w  w. j a v a2s.  c om
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
void handleActionNdefDiscovered(Intent intent) {
    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
    final byte[] receivedKeyringBytes = msg.getRecords()[0].getPayload();

    importKeys(receivedKeyringBytes);
}

From source file:org.iotivity.base.examples.SimpleBase.java

@Override
public void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    Log.d(TAG, "onNewIntent with changes sending broadcast IN ");

    Intent i = new Intent();
    i.setAction(intent.getAction());//from   w  ww.  j a va 2 s. com
    i.putExtra(NfcAdapter.EXTRA_NDEF_MESSAGES, intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES));
    sendBroadcast(i);
    Log.d(TAG, "Initialize Context again resetting");
}

From source file:pl.edu.pw.eiti.groupbuying.partner.android.ClaimCouponsActivity.java

/**
  * Parses the NDEF Message from the intent and prints to the TextView
  *///  w w  w  . j a v  a 2  s .c o m
@TargetApi(Build.VERSION_CODES.GINGERBREAD_MR1)
private void processIntent(Intent intent) {
    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
    extractCouponInfo(new String(msg.getRecords()[0].getPayload()));
    setIntent(null);
}

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

void processIntent(Intent intent) {
    try {/*w w w.ja  va  2 s  . c o m*/
        Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);

        if (null != rawMsgs && rawMsgs.length > 0) {
            NdefMessage msg = (NdefMessage) rawMsgs[0];

            /*for(NdefRecord nR : msg.getRecords())
            {
            String tmpString = new String(nR.getPayload());
            Log.e("Found: ", tmpString);
            }*/

            currentDeviceID = "/zport/dmd/Devices/" + new String(msg.getRecords()[0].getPayload());

        }
    } catch (Exception e) {
        e.printStackTrace();
        BugSenseHandler.sendExceptionMessage("ViewZenossDeviceActivity", "processIntent", e);
        try {
            Toast.makeText(this, "There was a problem trying to find the device ID that was beamed",
                    Toast.LENGTH_SHORT).show();
        } catch (Exception e1) {
            BugSenseHandler.sendExceptionMessage("ViewZenossDeviceActivity", "processIntent Toast", e1);
        }
    } finally {
        try {
            triggerUIHandler.sendEmptyMessage(UI_POPULATE);
        } catch (Exception e) {
            BugSenseHandler.sendExceptionMessage("ViewZenossDeviceActivity", "processIntent", e);
        }
    }
}

From source file:de.stadtrallye.rallyesoft.ConnectionAssistantActivity.java

private void processNfcIntent(Intent intent) {
    Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
    // only one message sent during the beam
    NdefMessage msg = (NdefMessage) rawMsgs[0];

    readServerLoginJSON(new String(msg.getRecords()[0].getPayload()));
}

From source file:com.sftoolworks.nfcoptions.SelectActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_select);

    nfcAdapter = NfcAdapter.getDefaultAdapter(this);
    pendingIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, this.getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

    Intent intent = getIntent();
    Parcelable[] rawMessages = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);

    String title = getString(R.string.default_select_title);

    TextView textViewBottom = (TextView) findViewById(R.id.textView2);
    textViewBottom.setText("");

    if (rawMessages != null) {

        ArrayList<Object> entries = new ArrayList<Object>();

        String data = null;/*w  w  w . ja v a 2s .co  m*/

        for (Parcelable rawMessage : rawMessages) {
            NdefMessage message = (NdefMessage) rawMessage;
            NdefRecord[] records = message.getRecords();
            if (records.length > 1) {
                byte[] bArray = records[1].getPayload();
                byte languageLength = bArray[0];

                languageLength++; // because of the length byte

                data = new String(bArray, languageLength, bArray.length - languageLength);
            }
        }

        try {
            JSONObject json = (JSONObject) new JSONTokener(data).nextValue();
            if (json.has("title"))
                title = json.getString("title");
            if (json.has("key"))
                selectKey = json.getString("key");
            if (json.has("options")) {
                JSONArray arr = json.getJSONArray("options");
                for (int i = 0; i < arr.length(); i++) {
                    entries.add(parseJObject(arr.getJSONObject(i)));
                }
            }

            ListView list = (ListView) findViewById(R.id.listView1);
            list.setAdapter(new OptionListAdapter(this, entries.toArray()));

            list.setOnItemClickListener(new ListView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int index, long id) {
                    CheckBox cb = (CheckBox) view.findViewById(R.id.optionListCheckBox);
                    cb.setChecked(!cb.isChecked());
                }
            });

            textViewBottom.setText(getString(R.string.tap_again));

        } catch (Exception e) {
            String message = getString(R.string.json_err);
            message += "\n";
            message += e.getMessage();

            Toast.makeText(this, message, Toast.LENGTH_LONG).show();

            Log.d(TAG, getString(R.string.json_err));
            Log.d(TAG, e.toString());
            Log.d(TAG, data);
        }
    } else {
        title = getString(R.string.no_tag);
    }

    TextView msg = (TextView) findViewById(R.id.textView1);
    msg.setText(title);

}

From source file:org.thinkfree.axihome.NFC.TagViewer.java

void resolveIntent(Intent intent) {

    Log.e(TAG, "Tag detected");
    String action = intent.getAction();

    Log.e(TAG, action);/* w w  w .  j  a v  a  2 s . c  o  m*/

    if (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
            Log.e(TAG, "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 };
        }
        // Setup the views
        processMessage(msgs);
    } else {

        Log.e(TAG, "Unknown intent " + intent);
        finish();
        return;
    }
}

From source file:org.thialfihar.android.apg.ui.ImportKeysActivity.java

/**
 * NFC: Parses the NDEF Message from the intent and prints to the TextView
 *//*from   ww  w.j  a va  2  s  .c  om*/
@SuppressLint("NewApi")
void handleActionNdefDiscovered(Intent intent) {
    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
    byte[] receivedKeyringBytes = msg.getRecords()[0].getPayload();

    Intent importIntent = new Intent(this, ImportKeysActivity.class);
    importIntent.setAction(ImportKeysActivity.ACTION_IMPORT_KEY);
    importIntent.putExtra(ImportKeysActivity.EXTRA_KEY_BYTES, receivedKeyringBytes);

    handleActions(null, importIntent);
}

From source file:com.evandroid.musica.MainLyricActivity.java

@TargetApi(14)
private Lyrics getBeamedLyrics(Intent intent) {
    Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
    // only one message sent during the beam
    if (rawMsgs != null && rawMsgs.length > 0) {
        NdefMessage msg = (NdefMessage) rawMsgs[0];
        // record 0 contains the MIME type, record 1 is the AAR, if present
        NdefRecord[] records = msg.getRecords();
        if (records.length > 0) {
            try {
                return Lyrics.fromBytes(records[0].getPayload());
            } catch (IOException | ClassNotFoundException e) {
                e.printStackTrace();//from w  w w.  ja  v  a 2s . co m
            }
        }
    }
    return null;
}

From source file:com.sixwonders.courtkiosk.CheckInActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 888) {
        if (resultCode == Pdf417ScanActivity.RESULT_OK && data != null) {
            // perform processing of the data here

            // for example, obtain parcelable recognition result
            Bundle extras = data.getExtras();
            Parcelable[] resultArray = data
                    .getParcelableArrayExtra(Pdf417ScanActivity.EXTRAS_RECOGNITION_RESULT_LIST);
            // Each element in resultArray inherits BaseRecognitionResult class and
            // represents the scan result of one of activated recognizers that have
            // been set up. More information about this can be found in
            // "Recognition settings and results" chapter
            ConnectionUtil connectionUtil = new ConnectionUtil();
            connectionUtil.authCall("Todd", "Lewis", "05/21/1953", (AsyncResponse) activity);
        }/*from   w ww .  ja va  2  s  .  c  om*/
    }
}