android 获取本机的一些信息(imsi,imei....不断更新中)

        //获取手机IMSI,imei
        TelephonyManager mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        String imsi = mTelephonyMgr.getSubscriberId();
        String imei = mTelephonyMgr.getDeviceId();
        
        Log.i("Info",imsi);
        Log.i("Info",imei);
        
        //获取版本号和版本名称
        try {
int versioncode = getPackageManager().getPackageInfo("test.zhiyou.app", 0).versionCode;
String versionName = this.getPackageName();
Log.i("Info",String.valueOf(versioncode));
Log.i("Info",versionName);

} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.i("Info",String.valueOf(versioncode));
Log.i("Info",versionName);
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();

}


另外不要忘了在AndroidManifest.xml中加上读取手机状态的权限

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

你可能感兴趣的:(android,String,service,手机)