I am trying to write an NFC tag with coordinates (latitude and longitude), in the following manner:
This is inside onCreate()
:
btnWriteMap.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String latitude = lat.getText().toString();
String longitude = lon.getText().toString();
urlAddress = "geo:"+latitude+","+longitude;
TextView messageText = (TextView)findViewById(R.id.txtMessage);
messageText.setText("Touch NFC Tag to share GEO location\n"+
"Latitude: "+latitude+"\nLongitude: "+longitude);
}
});
mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
mPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
mFilters = new IntentFilter[] {
ndef,
};
mTechLists = new String[][] { new String[] { Ndef.class.getName() },
new String[] { NdefFormatable.class.getName() }};
The onNewIntent()
method:
@Override
public void onNewIntent(Intent intent) {
Log.i("Foreground dispatch", "Discovered tag with intent: " + intent);
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
String externalType = "nfclab.com:geoService";
NdefRecord extRecord = new NdefRecord(NdefRecord.TNF_EXTERNAL_TYPE, externalType.getBytes(), new byte[0], urlAddress.getBytes());
NdefMessage newMessage = new NdefMessage(new NdefRecord[] { extRecord});
writeNdefMessageToTag(newMessage, tag);
}
The code is a sample from a book. I have tested and the tag is indeed written with geo:lat,lon, of course with the coordinates I have in my EditTexts.
The problem occurs when I read the tag. It will just display (on the default Android Tags application) the following message:
vnd.android.nfc//ext/nfclab.com:geoService
What I want is for the Tags application to recognize that these are Google Maps coordinates and launch Maps with the coordinates. What should the externalType String contain? Do I need to use an Intent filter in my manifest?