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
Yes, createTextRecord is introduced in API 21, so you can't call it in the previous versions. https://developer.android.com/reference/android/nfc/NdefRecord.html
Check if your API level is 21 before to call createTextRecord.
public NdfeMessage create(String content){
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= android.os.Build.VERSION_CODES.LOLLIPOP){
NdefRecord record = NdefRecord.createTextRecord("en", content);
NdefMessage msg = new NdefMessage(new NdefRecord[]{record});
return msg;
} else{
return null;
}
}