This code works fine when I use it on a device with Android Lollipop (5.x) or Marshmallow (6.0):
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public NdefMessage createNdfMessage(String content) {
NdefRecord record = NdefRecord.createTextRecord("en", content);
NdefMessage msg = new NdefMessage(new NdefRecord[]{record});
return msg;
}
But when I try this on a device with Android 4.2.2 (API level 17) my app crashes. How can I use this code to create a Text record on API levels below 21 (that's the API level where the method NdefRecord.createTextRecord
became available)?
Aucun commentaire:
Enregistrer un commentaire