再談 android 設備SN的獲取 續 android 設備唯一碼的獲取,Cpu號,Mac地址

之前發過一篇文章獲取 


http://blog.csdn.net/hpccn/article/details/7872141

android 設備唯一碼的獲取,Cpu號,Mac地址

這個方法使用中發現一些不完美的地方.

--------------------------------------

新的方法:

在使用命令行, adb device 

adb devices
List of devices attached
0288504643dfbxxx    device

^__這個號做爲設備的SN號更適合一些.如何獲取此值?


使用  adb get-serialno 可以獲取 此值

$adb get-serialno

0288504643dfbxxx

一步步查找

$adb shell

$getprop

.... ...

[ro.boot.serialno]: [0288504643dfbxxx]

....

[ro.serialno]: [0288504643dfbxxx]


系統屬性中 這兩項值相同, 測試多臺設備後,此值均相同,



使用Java獲取

android.os.SystemProperties.get() 讀取系統屬性,的方法是系統隱藏,無法直接使用.

我們可以使用Java反射:


	static Method systemProperties_get = null;

	static String getAndroidOsSystemProperties(String key) {
		String ret;
			try {
				systemProperties_get = Class.forName("android.os.SystemProperties").getMethod("get", String.class);
				if ((ret = (String) systemProperties_get.invoke(null, key)) != null)
					return ret;
			} catch (Exception e) {
				e.printStackTrace();
				return null;
			}

		return "";
	}


測試代碼如下:

運行後,可以看我們讀取的設備SN號, 系統恢復出廠設置,刷機,均沒改變此SN.


		String []propertys = {"ro.boot.serialno", "ro.serialno"}; 
		for (String key : propertys){
//			String v = android.os.SystemProperties.get(key);
			String v = getAndroidOsSystemProperties(key);
			Log.e("", "get " + key + " : " + v);
		}



-------完----------



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章