Reputation: 11
i am working on Nexus 5X android Nougat 7.1.1 on BroadCastReceiver with action WifiManager.SCAN_RESULTS_AVAILABLE_ACTION defined in AndroidManifests.xml, but is don't work properly, is works only when i opened the wifi settings page.
Note: Since i have updated the device version from 7.0.0 to 7.1.1 this happening with me , before that, everything was working properly.
WiifiBroadcastReceiver.java
public class WifiBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if(action.equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) {
List<ScanResult> wifiScanResult = new ArrayList<>();
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
if (wifiManager.isWifiEnabled()) {
wifiScanResult = wifiManager.getScanResults();
}
}
}
}
AndroidManifests.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.TestApp">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".LauncherActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".WifiBroadcastReceiver">
<intent-filter>
<action android:name="android.net.wifi.SCAN_RESULTS" />
</intent-filter>
</receiver>
</application>
</manifest>
Upvotes: 1
Views: 744
Reputation: 11
You need to activate the GPS on your device.Then it will work.
Upvotes: 0
Reputation: 41
It's the system error of the android 7.1.1.
Some devices have been updated to Android 7.1.2 where this error was fixed, another ones now have rollback to the previous version.
Upvotes: 1