-2

I am developing an app which reads NFC tags. If the tag is plain text, it gets displayed in a TextView. If it is a vCard, I want to pass the intent right through to the contacts where it can be handled the same way it would if there was no app in the foreground.

I know that I can insert a user using

Intent intent = new Intent(ContactsContract.Intents.Insert.ACTION);
intent.setType(ContactsContract.RawContacts.CONTENT_TYPE);
startActivity(intent);

but this would only open the contacts app without actually passing the data. Using the intent my app recieved, throws a NullPointerException (startActivity(recievedIntent)). This is probably because I handle the recieving and the passing in a different method, even though I pass the intent from one method to the other.

Thank you for your time!

Moritz K
  • 11
  • 2

1 Answers1

0

You can transfer the data to another activity this way, e.g. in your onNewIntent(Intent intent) method:

Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
        Intent myintent = new Intent(this, yourIntentActivity.class);
        myintent.setAction(NfcAdapter.ACTION_NDEF_DISCOVERED);
        myintent.putExtra(NfcAdapter.EXTRA_NDEF_MESSAGES, rawMsgs);
        myintent.putExtra(NfcAdapter.EXTRA_TAG, intent.getParcelableExtra(NfcAdapter.EXTRA_TAG));
        startActivity(myintent);
corvairjo
  • 843
  • 1
  • 14
  • 25