Question

I have a complete code that scans the near WiFi hot spots and place them in a list but I'm getting the following message in the Console window:

[2014-02-21 15:21:40 - WIFI] Failed to install WIFI.apk on device 'emulator-5554!
[2014-02-21 15:21:40 - WIFI] (null)
[2014-02-21 15:21:41 - WIFI] Launch canceled!

The code dose not have errors (shown below):

MainActivity.java

public class MainActivity extends Activity {
    WifiManager mainWifiObj;
    WifiScanReceiver wifiReciever;
    ListView list;
    String wifis[];

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        list = (ListView) findViewById(R.id.listView1);
        mainWifiObj = (WifiManager) getSystemService(Context.WIFI_SERVICE);
        wifiReciever = new WifiScanReceiver();
        mainWifiObj.startScan();
    }

    protected void onPause() {
        unregisterReceiver(wifiReciever);
        super.onPause();
    }

    protected void onResume() {
        registerReceiver(wifiReciever, new IntentFilter(
                WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
        super.onResume();
    }

    class WifiScanReceiver extends BroadcastReceiver {
        @SuppressLint("UseValueOf")
        public void onReceive(Context c, Intent intent) {
            List<ScanResult> wifiScanList = mainWifiObj.getScanResults();

            // String bssid = wifiInfo.getBSSID();

            wifis = new String[wifiScanList.size()];
            for (int i = 0; i < wifiScanList.size(); i++) {
                wifis[i] = ((wifiScanList.get(i)).toString());
                Log.i("Data", "ScanResult");

            }
            list.setAdapter(new ArrayAdapter<String>(getApplicationContext(),
                    android.R.layout.simple_list_item_1, wifis));

        }
    }
}

WIFI Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.wifi"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="19" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
        <activity
        android:name="com.example.wifi.MainActivity"
        android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
        android:name="com.example.wifi.ListWifiActivity"
        android:label="This activity has a list of wifi networks" >
        </activity>
    </application>
</manifest>

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:drawSelectorOnTop="false"
android:background="@android:color/background_dark"
android:listSelector="@android:color/darker_gray" >
</ListView>
</RelativeLayout>

The strings.xml file is shown below too because there was an error which was solves after modifing it:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">WIFI</string>
    <string name="action_settings">Settings</string>
    <string name="hello_world">Hello world!</string>
    <string name="title_activity_list_wifi">This activity has a list of wifi networks</string>
</resources>

The code is error free but I can not check its functionality without trying it.

Was it helpful?

Solution

In terms of running the app:

From this SO answer it appears that you can't use the emulator to scan WiFi connections. (thanks to @DimitarDimitrov for his answer on this)

Currently, while you can use your computer's Internet connection in the emulator, it's not reliable to use it for simulating Wi-Fi. The WifiManager gets confused when you switch/want to test your connectivity state.

More relevant is this:

While you can use your Internet for simulating HTTP connections and downloading data, finer control over Wi-Fi connectivity should better be done with a device.

I would suggest trying it on a device and proceeding from there.

From a little further reading From kmansoft.com on WiFi in the emulator

The emulator has no WiFi support. For your own apps, you can fake it by checking if running in the emulator. For other apps, you’re most likely out of luck.


In terms of the installation issue on the Emulator here are some links on this error:

Generally ADB timouts and not having sufficient PC power are the causes of the installer error.

Fail to install apk on emulator

In eclipse, you can increase the timeout. In Eclipse, Go to WINDOW-->Prefrences-->android-->DDMS>increase the timeout value. In my case it was 5000 & i incresed it to 10000 & it worked for me .

Also:

Close the emulator and launch the APP again. That would fix the issue. You might have kept the emulator open for quite some time without doing any activity.

Time out related

Yon can increase your adb timeout setting in eclipse. Go to Preferences-> Android-> DDMS-> find "ADB connection time out (ms)" and give some more higher value.

Also, try to see if your emulator in connected to the DDMS. Either check from DDMS view or run "ADB devices" in command prompt

Can you try it throgh ADB directly adb install -l -r WIFI.apk

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top