Android NdefMessage - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android NdefMessage class.

This code example shows how to use the following methods: toByteArray
            NdefRecord record = new NdefRecord(NdefRecord.TNF_MIME_MEDIA,
                    "text/x-su-a".getBytes(),
                    new byte[0], 
                    PreferenceManager.getDefaultSharedPreferences(this)
                            .getString("pin", "").getBytes());
            NdefMessage message = new NdefMessage(new NdefRecord[] {record });
 
            Ndef ndef = Ndef.get(tagFromIntent);
            if (ndef != null) {
                if (!ndef.isWritable()) {
                    Toast.makeText(this, "Tag not writeable", Toast.LENGTH_SHORT).show();
                    return; 
                } 
                 
                int maxSize = ndef.getMaxSize();
                 
                if (maxSize < message.toByteArray().length) {
                    Toast.makeText(this, "Tag not big enough", Toast.LENGTH_SHORT).show();
                    return; 
                } 

7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods:
    } 
 
    public void testPutSmallToDefaultServer() throws IOException { 
        SnepClient client = new SnepClient();
        client.connect();
        client.put(getSmallNdef());
        client.close();
    } 
 
    public void testPutLargeToDefaultServer() throws IOException { 
        SnepClient client = new SnepClient();
        client.connect();
        client.put(getLargeNdef());
        client.close();
    } 
 
    public void testPutTwiceToDefaultServer() throws IOException { 
        SnepClient client = new SnepClient();
        client.connect();
        client.put(getSmallNdef());

7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: toByteArray
      this.tag=tag;
    } 
     
    @Override 
    protected Void doInBackground(Void... arg0) {
      int size=msg.toByteArray().length;
 
      try { 
        Ndef ndef=Ndef.get(tag);
         
        if (ndef==null) {
          NdefFormatable formatable=NdefFormatable.get(tag);
           
          if (formatable!=null) {
            try { 
              formatable.connect();
               
              try { 
                formatable.format(msg);
              } 
Full Snippet Info
6
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods:
    } 
 
    public void testPutSmall() throws IOException { 
        SnepClient client = getSnepClient();
        client.connect();
        client.put(getSmallNdef());
        client.close();
    } 
 
    public void testPutLarge() throws IOException { 
        SnepClient client = getSnepClient();
        client.connect();
        client.put(getLargeNdef());
        client.close();
    } 
 
    public void testPutTwice() throws IOException { 
        SnepClient client = getSnepClient();
        client.connect();
        client.put(getSmallNdef());

7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: toByteArray
 
    /* 
     * Writes an NdefMessage to a NFC tag 
     */ 
    static boolean writeTag(NdefMessage message, Tag tag) {
        int size = message.toByteArray().length;
        try { 
            Ndef ndef = Ndef.get(tag);
            if (ndef != null) {
                ndef.connect();
                if (!ndef.isWritable()) {
                    Log.e(TAG, "Tag is not writable!");
                    return false; 
                } 
                if (ndef.getMaxSize() < size) {
                    Log.e(TAG,
                            "Tag exceeds max ndef message size! [" + size + " > "
                                    + ndef.getMaxSize() + "]");
                    return false; 
                } 
Full Snippet Info
6
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods:
        public NdefMessage[] msgs;
 
        public TagDescription(String title, byte[] bytes) {
            this.title = title;
            try { 
                msgs = new NdefMessage[] {new NdefMessage(bytes)};
            } catch (final Exception e) {
                throw new RuntimeException("Failed to create tag description", e);
            } 
        } 
 
        @Override 
        public String toString() {
            return title;
        } 
    } 
 
    @Override 
    public void onCreate(Bundle savedState) {
        super.onCreate(savedState);
Full Snippet Info
6
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods:
    } 
 
    private NdefMessage getSmallNdef() {
        NdefRecord rec = new NdefRecord(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_URI,
                new byte[] { 'A' }, "http://android.com".getBytes());
        return new NdefMessage(new NdefRecord[] { rec });
    } 
 
    private NdefMessage getLargeNdef() {
        int size = 500;
        StringBuffer string = new StringBuffer(size);
        for (int i = 0; i < size; i++) {
            string.append('A' + (i % 26));
        } 
        NdefRecord rec = new NdefRecord(NdefRecord.TNF_MIME_MEDIA, "text/plain".getBytes(),
                new byte[] { 'B' }, string.toString().getBytes());
        return new NdefMessage(new NdefRecord[] { rec });
    } 
 
    private SnepClient getSnepClient() { 
Full Snippet Info
6
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: setNdefPushMessage
  @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());
    } 
  } 
 
} 
Full Snippet Info
6
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: toByteArray
        /** 
         * Converts an NdefMessage to ContentValues that can be insrted into this table. 
         */ 
        public static ContentValues toValues(Context context, NdefMessage msg, boolean isStarred,
                boolean isMyTag, long date) {
            ParsedNdefMessage parsedMsg = NdefMessageParser.parse(msg);
            ContentValues values = new ContentValues();
            values.put(BYTES, msg.toByteArray());
            values.put(DATE, date);
            values.put(STARRED, isStarred ? 1 : 0);
            values.put(IS_MY_TAG, isMyTag ? 1 : 0);
            values.put(TITLE, parsedMsg.getSnippet(context, Locale.getDefault()));
            return values;
        } 
    } 
} 
Full Snippet Info
6
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods:
}; 
 
@Override 
public NdefMessage createNdefMessage(NfcEvent event) {
	 NdefRecord uriRecord = NdefRecord.createUri(url);
	    return new NdefMessage(new NdefRecord[] { uriRecord });
} 
 
 
} 
Full Snippet Info
6
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE

Related Android NdefMessage Questions & Answers:

See Code Examples for Android NdefMessage Methods: