不是crash
,但是当我调用getScanResults()
方法时,它没有给我结果。我得到了:
2019-01-13 21:40:57.581 3647-3910/? E/ConnectivityService: RemoteException caught trying to send a callback msg for NetworkRequest [ LISTEN id=1104, [ Capabilities: INTERNET&NOT_RESTRICTED&TRUSTED] ]
我不知道该怎么做才能帮助我
这是我的代码
public class MainActivity extends AppCompatActivity {
Socket socket;
WifiManager wifiManager;
Network network;
ConnectivityManager connectivityManager;
WifiConfiguration wifiConfiguration;
IntentFilter intentFilter;
BroadcastReceiver broadcastReceiver=new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.i("TAG00","scanning");
boolean success = intent.getBooleanExtra(
WifiManager.EXTRA_RESULTS_UPDATED, false);
if(success) {
Scan();
}
}
};
@Override
protected void onDestroy() {
super.onDestroy();
unregisterReceiver(broadcastReceiver);
Scan();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
socket =new Socket();
//Intent myIntent = new Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS);
// startActivity(myIntent);
intentFilter=new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
wifiManager= (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
connectivityManager=(ConnectivityManager) getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
List<WifiConfiguration> x= wifiManager.getConfiguredNetworks();
for(WifiConfiguration a:x){
// Log.i("TAG00",a.SSID);
// Log.i("TAG00",a.BSSID);
if(a.SSID.equals("MyNetwork"));
wifiManager.startScan();
registerReceiver(broadcastReceiver,intentFilter);
}
for(Network n:connectivityManager.getAllNetworks()){
NetworkInfo networkInfo=connectivityManager.getNetworkInfo(n);
// Log.i("TAG00",String.valueOf(networkInfo.getExtraInfo()));
// Log.i("TAG00",String.valueOf(networkInfo));
}
}
public void WifiOn(View view){
wifiManager.setWifiEnabled(true);
}
public void WifiOFF(View view){
wifiManager.setWifiEnabled(false);
}
public void Scan (){
Log.i("TAG00","method called");
ArrayList<ScanResult>results= new ArrayList<>( wifiManager.getScanResults());
int data=results.size();
Log.i("TAG00",String.valueOf(data));
ArrayList<ScanResult> arrayList=new ArrayList<>(results);
for(ScanResult scanResult:arrayList){
Log.i("TAG00",String.valueOf(scanResult.SSID));
}
}
}
My Uses permissions:
<uses-permission android:name="android.permission.LOCATION_HARDWARE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_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.INTERNET"/>
enter code here