我想獲得有關我連接到的無線網絡的一些信息,但我不斷收到有關我的準備的錯誤信息,但我想他們應該沒問題。你能幫我一下嗎?Android中的准許和wifi問題
我的logcat
中的第一行描述了這個問題。該生產線是一個地方我叫wifi.getConnectionInfo();
我的Java代碼:
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
// private ConnectivityReceiver receiver = null;
// private TextView txtNetworkInfo = null;
private WifiManager wifi;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button b = (Button) findViewById(R.id.button1);
Button b2 = (Button) findViewById(R.id.button2);
wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
b.setOnClickListener(new OnClickListener(){
public void onClick(View arg0) {
// TODO Auto-generated method stub
wifi.getConnectionInfo();
// startService(new Intent(MainActivity.this, CheckService.class));
}
});
b2.setOnClickListener(new OnClickListener(){
public void onClick(View arg0) {
// TODO Auto-generated method stub
// stopService(new Intent(MainActivity.this, CheckService.class));
}
});
}
}
而且我logcat-
11-15 18:08:37.583: E/AndroidRuntime(28200): FATAL EXCEPTION: main
11-15 18:08:37.583: E/AndroidRuntime(28200): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jesper.soundchange/com.jesper.soundchange.MainActivity}: java.lang.SecurityException: WifiService: Neither user 10067 nor current process has android.permission.ACCESS_WIFI_STATE.
11-15 18:08:37.583: E/AndroidRuntime(28200): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2787)
11-15 18:08:37.583: E/AndroidRuntime(28200): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2803)
11-15 18:08:37.583: E/AndroidRuntime(28200): at android.app.ActivityThread.access$2300(ActivityThread.java:135)
11-15 18:08:37.583: E/AndroidRuntime(28200): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2136)
11-15 18:08:37.583: E/AndroidRuntime(28200): at android.os.Handler.dispatchMessage(Handler.java:99)
11-15 18:08:37.583: E/AndroidRuntime(28200): at android.os.Looper.loop(Looper.java:144)
11-15 18:08:37.583: E/AndroidRuntime(28200): at android.app.ActivityThread.main(ActivityThread.java:4937)
11-15 18:08:37.583: E/AndroidRuntime(28200): at java.lang.reflect.Method.invokeNative(Native Method)
11-15 18:08:37.583: E/AndroidRuntime(28200): at java.lang.reflect.Method.invoke(Method.java:521)
11-15 18:08:37.583: E/AndroidRuntime(28200): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
11-15 18:08:37.583: E/AndroidRuntime(28200): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
11-15 18:08:37.583: E/AndroidRuntime(28200): at dalvik.system.NativeStart.main(Native Method)
11-15 18:08:37.583: E/AndroidRuntime(28200): Caused by: java.lang.SecurityException: WifiService: Neither user 10067 nor current process has android.permission.ACCESS_WIFI_STATE.
11-15 18:08:37.583: E/AndroidRuntime(28200): at android.os.Parcel.readException(Parcel.java:1247)
11-15 18:08:37.583: E/AndroidRuntime(28200): at android.os.Parcel.readException(Parcel.java:1235)
11-15 18:08:37.583: E/AndroidRuntime(28200): at android.net.wifi.IWifiManager$Stub$Proxy.getDhcpInfo(IWifiManager.java:754)
11-15 18:08:37.583: E/AndroidRuntime(28200): at android.net.wifi.WifiManager.getDhcpInfo(WifiManager.java:712)
11-15 18:08:37.583: E/AndroidRuntime(28200): at com.jesper.soundchange.MainActivity.onCreate(MainActivity.java:30)
11-15 18:08:37.583: E/AndroidRuntime(28200): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1069)
11-15 18:08:37.583: E/AndroidRuntime(28200): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2751)
我manifest-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jesper.soundchange"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="15" />
<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" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".CheckService"
android:label="My Service" >
</service>
</application>