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

  • SEARCH
  • Home
  • 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 6606625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:24:57+00:00 2026-05-25T19:24:57+00:00

I’m in the process of learning the android api. However, when I try to

  • 0

I’m in the process of learning the android api. However, when I try to get info about wifi my program is closing unexpectedly:

here is the code:

package com.example.helloandroid;    

import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.content.BroadcastReceiver;
import android.content.Context;

public class HelloAndroid extends Activity {
    /** Called when the activity is first created. */

    WifiManager wifi;
    BroadcastReceiver receiver;

    TextView textStatus;
    Button buttonScan;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        TextView tv = new TextView(this);
        tv.setText("Hello, Android");
        setContentView(tv);

        wifi = (WifiManager)getSystemService(Context.WIFI_SERVICE);
     //   WifiInfo info = wifi.getConnectionInfo();
       // tv.append("\n\nWiFi Status: " + info.toString());

    }
}

The code above runs, but as soon as I uncomment the line:
WifiInfo info = wifi.getConnectionInfo();

It says that my program has closed unexpectedly. I’m not sure what I’m doing wrong. Any help would be appreciated.

I am using the simulator.

Thanks

UPDATE: if I write out the wifi obj:

wifi = (WifiManager)getSystemService(Context.WIFI_SERVICE);
tv.append(wifi.toString());

the app run and tv says:

android.net.wifi.
WifiManager@4051c960

UPDATE:
LogCat:

09-22 14:56:51.387: ERROR/AndroidRuntime(408): FATAL EXCEPTION: main
09-22 14:56:51.387: ERROR/AndroidRuntime(408): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.helloandroid/com.example.helloandroid.HelloAndroid}: java.lang.SecurityException: WifiService: Neither user 10034 nor current process has android.permission.ACCESS_WIFI_STATE.
09-22 14:56:51.387: ERROR/AndroidRuntime(408):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
09-22 14:56:51.387: ERROR/AndroidRuntime(408):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
09-22 14:56:51.387: ERROR/AndroidRuntime(408):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
09-22 14:56:51.387: ERROR/AndroidRuntime(408):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
09-22 14:56:51.387: ERROR/AndroidRuntime(408):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-22 14:56:51.387: ERROR/AndroidRuntime(408):     at android.os.Looper.loop(Looper.java:123)
09-22 14:56:51.387: ERROR/AndroidRuntime(408):     at android.app.ActivityThread.main(ActivityThread.java:3683)
09-22 14:56:51.387: ERROR/AndroidRuntime(408):     at java.lang.reflect.Method.invokeNative(Native Method)
09-22 14:56:51.387: ERROR/AndroidRuntime(408):     at java.lang.reflect.Method.invoke(Method.java:507)
09-22 14:56:51.387: ERROR/AndroidRuntime(408):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-22 14:56:51.387: ERROR/AndroidRuntime(408):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-22 14:56:51.387: ERROR/AndroidRuntime(408):     at dalvik.system.NativeStart.main(Native Method)
09-22 14:56:51.387: ERROR/AndroidRuntime(408): Caused by: java.lang.SecurityException: WifiService: Neither user 10034 nor current process has android.permission.ACCESS_WIFI_STATE.
09-22 14:56:51.387: ERROR/AndroidRuntime(408):     at android.os.Parcel.readException(Parcel.java:1322)
09-22 14:56:51.387: ERROR/AndroidRuntime(408):     at android.os.Parcel.readException(Parcel.java:1276)
09-22 14:56:51.387: ERROR/AndroidRuntime(408):     at android.net.wifi.IWifiManager$Stub$Proxy.getConnectionInfo(IWifiManager.java:591)
09-22 14:56:51.387: ERROR/AndroidRuntime(408):     at android.net.wifi.WifiManager.getConnectionInfo(WifiManager.java:605)
09-22 14:56:51.387: ERROR/AndroidRuntime(408):     at com.example.helloandroid.HelloAndroid.onCreate(HelloAndroid.java:35)
09-22 14:56:51.387: ERROR/AndroidRuntime(408):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-22 14:56:51.387: ERROR/AndroidRuntime(408):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
09-22 14:56:51.387: ERROR/AndroidRuntime(408):     ... 11 more
  • 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-25T19:24:57+00:00Added an answer on May 25, 2026 at 7:24 pm

    Not certain if it’s supported on emmulator but on a real device I think you would need to have the following permission in your manifest:

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

    If you were to look at the logcat output for errors when it closes you should see something to the effect of not having a permission…or maybe some other tidbit of info that would help others provide you some guidance. See: http://developer.android.com/guide/developing/tools/adb.html#logcat

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have thousands of HTML files to process using Groovy/Java and I need to
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm making a simple page using Google Maps API 3. My first. One marker
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.