Showing posts with label uid. Show all posts
Showing posts with label uid. Show all posts

Tuesday, 2 December 2014

NFC Mifare UID (Card Serial Number) reverse issue

If you are using NFC in your application, you should be careful while using UID of NFC card.

When any card is manufactured, it will be assigned a card serial number and it must be there if there is no any data.

When you try to fetch that UID using Android SDK NFC tag technology, it will return you UID in reverse order.

Generally when card ia manufactured, bytes are stored in LSB (Least Significant Byte) order while when Android read card serial number, it will read in MSB(Most Significant Byte) fashion.

For example. Any card has UID "12345678" then in MSB fashion, it will be like "78563412". 
So you need to convert this order from MSB to LSB.

Following short of code will help you to do this.

 String cardID = getHax(tag.getId());  
 String cardIdArr[] = cardId.split(" ");  
 String reverseCardId = "";  
 for (int i=0;i < cardIdArr.length;i++)  
 {  
   reverseCardId += cardIdArr[i];  
 }  
 Log.d("reverse"," card id = " + reverseCardId );  

Thursday, 28 March 2013

Android Unique Identificatin Numer

How to get android unique id number?

 
Purpose
Some times, when we are integrate our android application with server, its requirement of server that it can identify every android device uniquely. So to do that, we will learn how to get android id from device.

Android Id
A 64-bit number (as a hex string) that is randomly generated on the device's first boot and should remain constant for the lifetime of the device. (The value may change if a factory reset is performed on the device.)

Code
package com.did;

import android.app.Activity;
import android.os.Bundle;
import android.provider.Settings.Secure;
import android.util.Log;

public class DevideIdActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        String android_id = Secure.getString(this.getContentResolver(),
                Secure.ANDROID_ID);
       
        Log.d("Android","Android ID : "+android_id);
    }
}


 Output

download.jpg