android logcat" android.permission.LOCATION_HARDWARE"抛出:SecurityException

时间:2015-09-12 16:18:53

标签: android wifi android-manifest android-permissions

我必须使用startCustomizedScan(ScanSettings requested)功能。请求扫描指定频道列表中的接入点。每个信道由其频率以MHz为单位指定,例如" 2437"

我的完整代码是听到的。

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button scanButton = (Button)findViewById(R.id.button1);
        scanButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                WifiManager wifiManager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
                ScanSettings scanSettings = new ScanSettings();
                addWifiChannel(scanSettings, 11);
                wifiManager.startCustomizedScan(scanSettings);
            }
        });
    }

    public WifiChannel createWifiChannel(int channel) {
        WifiChannel wifiChannel = new WifiChannel();
        wifiChannel.channelNum = channel;
        //wifiChannel.freqMHz = getFrequencyFromChannel(channel);
        return wifiChannel;
    }

    public void addWifiChannel(ScanSettings scanSettings, int channel) {
        if (scanSettings.channelSet == null) scanSettings.channelSet = new ArrayList<WifiChannel>();
        scanSettings.channelSet.add(createWifiChannel(channel));
    }

    private final static ArrayList<Integer> channelsFrequency = new ArrayList<Integer>(
            Arrays.asList(0, 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447,
                    2452, 2457, 2462, 2467, 2472, 2484));
    public static Integer getFrequencyFromChannel(int channel) {
        return channelsFrequency.get(channel);
    }

    public static int getChannelFromFrequency(int frequency) {
        return channelsFrequency.indexOf(Integer.valueOf(frequency));
    }

}

我的Manifaste文件在这里:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.custom.wifiscan"
    android:sharedUserId="com.example.android"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="21"
        android:targetSdkVersion="21" />

    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.LOCATION_HARDWARE" />

但我的应用程序运行真实设备(LG G3在5.0中运行)应用程序停止

09-12 19:08:00.391: E/AndroidRuntime(23766): FATAL EXCEPTION: main
09-12 19:08:00.391: E/AndroidRuntime(23766): Process: com.custom.wifiscan, PID: 23766
09-12 19:08:00.391: E/AndroidRuntime(23766): java.lang.SecurityException: LocationHardware: Neither user 10246 nor current process has android.permission.LOCATION_HARDWARE.
09-12 19:08:00.391: E/AndroidRuntime(23766):    at android.os.Parcel.readException(Parcel.java:1540)
09-12 19:08:00.391: E/AndroidRuntime(23766):    at android.os.Parcel.readException(Parcel.java:1493)
09-12 19:08:00.391: E/AndroidRuntime(23766):    at android.net.wifi.IWifiManager$Stub$Proxy.startScan(IWifiManager.java:984)
09-12 19:08:00.391: E/AndroidRuntime(23766):    at android.net.wifi.WifiManager.startCustomizedScan(WifiManager.java:1037)
09-12 19:08:00.391: E/AndroidRuntime(23766):    at com.custom.wifiscan.MainActivity$1.onClick(MainActivity.java:30)
09-12 19:08:00.391: E/AndroidRuntime(23766):    at android.view.View.performClick(View.java:4763)
09-12 19:08:00.391: E/AndroidRuntime(23766):    at android.view.View$PerformClick.run(View.java:19821)
09-12 19:08:00.391: E/AndroidRuntime(23766):    at android.os.Handler.handleCallback(Handler.java:739)
09-12 19:08:00.391: E/AndroidRuntime(23766):    at android.os.Handler.dispatchMessage(Handler.java:95)
09-12 19:08:00.391: E/AndroidRuntime(23766):    at android.os.Looper.loop(Looper.java:135)
09-12 19:08:00.391: E/AndroidRuntime(23766):    at android.app.ActivityThread.main(ActivityThread.java:5274)
09-12 19:08:00.391: E/AndroidRuntime(23766):    at java.lang.reflect.Method.invoke(Native Method)
09-12 19:08:00.391: E/AndroidRuntime(23766):    at java.lang.reflect.Method.invoke(Method.java:372)
09-12 19:08:00.391: E/AndroidRuntime(23766):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:909)
09-12 19:08:00.391: E/AndroidRuntime(23766):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:704)

android.permission.LOCATION_HARDWARE错误是什么。我该如何解决这个错误 请有人给我一些见解, 最好的方面, 感谢。

1 个答案:

答案 0 :(得分:1)

该应用是否以系统应用的形式运行?因为LOCATION_HARDWARE需要系统级权限。