开发者

android scan for wifi network

开发者 https://www.devze.com 2023-01-15 07:05 出处:网络
i am trying out this code for scanning wifi networks but getting null pointer exception not sure what problem i registered all permission in manifest.

i am trying out this code for scanning wifi networks but getting null pointer exception not sure what problem i registered all permission in manifest.

IntentFilter i = new IntentFilter();
    i.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);

    registerReceiver(new BroadcastReceiver(){

            @Override

            public void onReceive(Context context, Intent intent) {
                // TODO Auto-generated method stub
                Log.i(TAG, "opening wifimanager");
                WifiManager mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
                mWifiManager.getSc开发者_如何学CanResults();

            }
        }
    ,i);



        mWifiManager.startScan();


Are you testing this on a device or on a stimulator. And have you added the following permissions on your Manifest

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>
0

精彩评论

暂无评论...
验证码 换一张
取 消