當需要知道多少人使用過我們開發的 APPS,或想知道利用 APPS到我們網站下載資料的實際人數,便需要讀取每部手機的唯一身份號碼,其中讀取手機的Device ID 或 WiFi MAC 址址都是可行的方法, 詳情可參考下面程式
ReadmobilenoActivity.java 程式內容
package sample.mobileno;
import android.app.Activity;
import android.content.Context;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.widget.TextView;
public class ReadmobilenoActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final TelephonyManager tm = (TelephonyManager) getBaseContext().getSystemService(Context.TELEPHONY_SERVICE);
final WifiManager wm = (WifiManager) getBaseContext().getSystemService(Context.WIFI_SERVICE);
final TextView finalstring = (TextView)findViewById(R.id.textView1); //Show the text number
final TextView finalstring2 = (TextView)findViewById(R.id.textView2); //Show the text number
final String tmDevice, tmWifiMac;
tmDevice = "Device ID is : " + tm.getDeviceId();
finalstring.setText(tmDevice);
tmWifiMac = "Mac of Wifi is : " + wm.getConnectionInfo().getMacAddress();
finalstring2.setText(tmWifiMac);
}
}