获取手机串号 所需权限

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


/**
	 * 手机串号
	 * @return
	 */
	private String getIMIE() {
		
		TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);		
		String imie = telephonyManager.getDeviceId();
		return imie;
	}
如果不加上上面的权限,会报下面的错误
报错信息:

07-10 06:36:03.799: E/AndroidRuntime(5923): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.cn.myvdun/com.cn.myvdun.VdunActivity}:
java.lang.NullPointerException
07-10 06:36:03.799: E/AndroidRuntime(5923): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
07-10 06:36:03.799: E/AndroidRuntime(5923): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
07-10 06:36:03.799: E/AndroidRuntime(5923): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
07-10 06:36:03.799: E/AndroidRuntime(5923): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
07-10 06:36:03.799: E/AndroidRuntime(5923): at android.os.Handler.dispatchMessage(Handler.java:99)
07-10 06:36:03.799: E/AndroidRuntime(5923): at android.os.Looper.loop(Looper.java:123)
07-10 06:36:03.799: E/AndroidRuntime(5923): at android.app.ActivityThread.main(ActivityThread.java:3683)
07-10 06:36:03.799: E/AndroidRuntime(5923): at java.lang.reflect.Method.invokeNative(Native Method)
07-10 06:36:03.799: E/AndroidRuntime(5923): at java.lang.reflect.Method.invoke(Method.java:507)
07-10 06:36:03.799: E/AndroidRuntime(5923): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-10 06:36:03.799: E/AndroidRuntime(5923): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-10 06:36:03.799: E/AndroidRuntime(5923): at dalvik.system.NativeStart.main(Native Method)
07-10 06:36:03.799: E/AndroidRuntime(5923): Caused by: java.lang.NullPointerException
07-10 06:36:03.799: E/AndroidRuntime(5923): at com.cn.myvdun.VdunActivity.setPassword(VdunActivity.java:166)
07-10 06:36:03.799: E/AndroidRuntime(5923): at com.cn.myvdun.VdunActivity.init(VdunActivity.java:116)
07-10 06:36:03.799: E/AndroidRuntime(5923): at com.cn.myvdun.VdunActivity.onCreate(VdunActivity.java:79)
07-10 06:36:03.799: E/AndroidRuntime(5923): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-10 06:36:03.799: E/AndroidRuntime(5923): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
07-10 06:36:03.799: E/AndroidRuntime(5923): ... 11 more

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