Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Android
I am trying to get the signal strength info from the all the available wifi access points but it doesnt work... Its always returning some null exception it seems. I tried to run it in mobile also but its not working. I have pointed out the line which is creating error by placing a comment in bold.

package a.c;
 
import java.util.ArrayList; 
import java.util.List;
 
import a.c.WifiActivity.WifiReceiver; 
import android.app.Activity; 
import android.content.BroadcastReceiver; 
import android.content.Context; 
import android.content.Intent; 
import android.content.IntentFilter; 
import android.net.wifi.ScanResult; 
import android.net.wifi.WifiManager; 
import android.os.Bundle; 
import android.widget.TextView; 
import android.widget.Toast; 
 
public class WifiActivity extends Activity { 
private WifiManager mainWifi; 
private WifiReceiver receiverWifi;
 
TextView sig;
 
/** Called when the activity is first created. */
 
@Override
 
public void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.main); 
mainWifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); 
receiverWifi = new WifiReceiver(); 
registerReceiver(receiverWifi, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)); 
}
 
class WifiReceiver extends BroadcastReceiver { 
public void onReceive(Context c, Intent intent) { 
List wifiList = mainWifi.getScanResults(); 
for (int i = 0; i < wifiList.size(); i++) { 
ScanResult scanResult = wifiList.get(i); 
// I have to put a try catch block here otherwise it returns an exception. 
try{ 
sig.append(scanResult.level+";"); 
} 
catch(exception e){}
}
} 
}
}

Can anyone help me with the code. I dont know what to do to get the signal strength info from the access points.There are access points nearby but im not able get the strength.If anyone could provide the code or any help then i would be thankful. Note: I have added the required permission to access wifistate in the manifest also so its not a problem there.
Posted 26-Mar-12 22:22pm
Edited 26-Mar-12 22:25pm
JF201553.4K
v2
Comments
Manfred R. Bihy at 27-Mar-12 4:21am
   
I just want to let you know that telling us what exception is occurring and what the message is would be of tremendous help to us in unraveling this mystery.
prajnavantha at 27-Mar-12 12:48pm
   
Its actually a null pointer exception.....

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I don't have any solution but i learned a lot of things here and it really works.. it helps a lot.
 
http://www.2012kiaoptima.com
http://www.adsonoahu.com
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 2 Apr 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100