Code example for NdefMessage

Methods: setNdefPushMessage

0
  @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
  private void startNfc(String uri) {
 
    if(getActivity() != null && NfcAdapter.getDefaultAdapter(getActivity()) != null) {
 
      NdefMessage message = new NdefMessage(new NdefRecord[] { NdefRecord.createUri(uri) });
      NfcAdapter.getDefaultAdapter(getActivity()).setNdefPushMessage(message, getActivity());
    } 
  } 
 
  @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
  private void stopNfc() { 
 
    if(getActivity() != null && NfcAdapter.getDefaultAdapter(getActivity()) != null) {
      NfcAdapter.getDefaultAdapter(getActivity()).setNdefPushMessage(null, getActivity());
    } 
  } 
 
}