Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4000508
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:47:25+00:00 2026-05-20T07:47:25+00:00

Sorry if it’s a silly question…i m only a beginner in android programming. i

  • 0

Sorry if it’s a silly question…i m only a beginner in android programming.

i want to make an array of signal levels and access point mac addresses. Later my goal is to POST these two arrays to a server using JSON for getting a web service. i cannot find a right way to make the array..though i m able to retrieve the wifi information that android provides. see the commented out statements in the Onreceive method of the following code.

package com.example.jsonwifi;


public class JsonWifi extends Activity {
    TextView mainText;
    WifiManager mainWifi;
    WifiReceiver receiverWifi;
    List<ScanResult> wifiList;
    StringBuilder sb = new StringBuilder();
    String[] apmacs;
    String[] levels;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    mainText = (TextView) findViewById(R.id.mainText);
    mainWifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);

    receiverWifi = new WifiReceiver();
    registerReceiver(receiverWifi, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
    mainWifi.startScan();
    mainText.setText("\nStarting Scan...\n");
}

@Override
public boolean onCreateOptionsMenu(Menu mn) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.layout.menu, mn);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection
    switch (item.getItemId()) {
    case R.id.refreshbt:
        mainWifi.startScan();
        mainText.setText("Starting Scan");
    default:
        return super.onOptionsItemSelected(item);
    }
}

protected void onPause() {
    unregisterReceiver(receiverWifi);

    super.onPause();
}

protected void onResume() {
    registerReceiver(receiverWifi, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
    Toast.makeText(getBaseContext(), "resumed", Toast.LENGTH_LONG).show();
    super.onResume();
}

class WifiReceiver extends BroadcastReceiver {

    public void onReceive(Context c, Intent intent) {
        sb = new StringBuilder();
        wifiList = mainWifi.getScanResults();
        for(int i = 0; i < wifiList.size(); i++){
            sb.append(new Integer(i+1).toString() + ".");
            sb.append(" SSID= ");
            sb.append((wifiList.get(i)).SSID.toString());
            sb.append("\n");
            sb.append("     BSSID= ");
            sb.append((wifiList.get(i)).BSSID.toString());
            sb.append(",");
            sb.append(" signal level= ");
            sb.append((wifiList.get(i)).level);
            sb.append("\n");

           // apmacs[]= (wifiList.get(i).BSSID);
           // levels[] = (wifiList.get(i).level);
        }
        mainText.setText(sb);
    }
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T07:47:26+00:00Added an answer on May 20, 2026 at 7:47 am

    seems like you want to build String arrays out of retrieved data stored in a List<ScanResult>.. I’d initialize the arrays to the size of the List and populate them in side the loop… like this

    See if this works.

        public void onReceive(Context c, Intent intent) {
                sb = new StringBuilder();
                wifiList = mainWifi.getScanResults();
    
                // initialize arrays here!
                apmacs = new String[wifiList.size( )];
                levels = new String[wifiList.size( )];
    
                for(int i = 0; i < wifiList.size(); i++){
                    sb.append(new Integer(i+1).toString() + ".");
    ..... more appends....
    
                   // populate the arrays                       
                   apmacs[i]= wifiList.get(i).BSSID;
                   levels[i] = String.valueOf( wifiList.get(i).level );
                }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry, the question is not programming related but I have nowhere else to ask,
Sorry for a long question but here goes. I am trying to modify the
Sorry if this is a newbie question. I have searched but found nothing... Using
Sorry for the long title. In essence, I want to accomplish the same thing
Sorry, lots of code coming up.. I saw another question like this that used
Sorry I didn't explain My problem correctly , My problem is that I have
Sorry for unclear title - I don't know how to describe that problem in
Sorry for the strange title. Here is my situation. I have a table of
(Sorry for the confusion. Previous $ sign occurred when I tried to simplify the
Sorry for the rubbish title but hopefully this will explain: Given the table name

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.