7
您好我有下面的代碼讀取網絡/ WIFI狀態:異常讀WIFI/3G州
public String getMacAddress() {
WifiManager wm = (WifiManager) context
.getSystemService(Context.WIFI_SERVICE);
return wm.getConnectionInfo().getMacAddress();
}
這將引發
Caused by: java.lang.SecurityException: WifiService: Neither user 10032 nor current process has android.permission.ACCESS_WIFI_STATE
而且
public boolean is3G() {
ConnectivityManager connectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
return !(connectivityManager.getNetworkInfo(
ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED || connectivityManager
.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED);
}
這將引發
Caused by: java.lang.SecurityException: ConnectivityService: Neither user 10032 nor current process has android.permission.ACCESS_NETWORK_STATE.
之前有人告訴我的權限,這是我的清單(相關部分):
<manifest>
<!-- usual tags for activitys... etc.. -->
<uses-permission android:name="android.permission.WRITE_OWNER_DATA" />
<uses-permission android:name="android.permission.READ_OWNER_DATA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<user-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<user-permission android:name="android.permission.ACCESS_WIFI_STATE" />
</manifest>
大聲笑,閱讀代碼後,我看到這個錯誤。謝謝。 – 2011-05-17 14:13:11