Don't crash if no NfcAdapter present; Replace constructor from API 16+

This commit is contained in:
fkloft 2014-01-26 15:33:17 +01:00
parent 23a092f187
commit bb31fbd9f8

View File

@ -149,7 +149,7 @@ public class IITC_Mobile extends Activity
registerReceiver(mBroadcastReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
final NfcAdapter nfc = NfcAdapter.getDefaultAdapter(this);
nfc.setNdefPushMessageCallback(this, this);
if (nfc != null) nfc.setNdefPushMessageCallback(this, this);
handleIntent(getIntent(), true);
}
@ -793,12 +793,17 @@ public class IITC_Mobile extends Activity
@Override
public NdefMessage createNdefMessage(final NfcEvent event) {
NdefRecord[] records;
if (mPermalink == null) { // no permalink yet, just provide AAR
return new NdefMessage(NdefRecord.createApplicationRecord(getPackageName()));
}
return new NdefMessage(
records = new NdefRecord[] {
NdefRecord.createApplicationRecord(getPackageName())
};
} else {
records = new NdefRecord[] {
NdefRecord.createUri(mPermalink),
NdefRecord.createApplicationRecord(getPackageName()));
NdefRecord.createApplicationRecord(getPackageName())
};
}
return new NdefMessage(records);
}
}