tags:

views:

39

answers:

1

I need to create a Robotium application that would use Settings application to turn ON/OFF WIFi from menu Settings->Wireless & networks->Wi-Fi. I managed to find some sample code here that demonstrates how to launch application by having apk file only. The problem is that my Robotium application should have the same signature with the (system) Settings application. While trying to run application I get the error message:

Test run failed: Permission Denial: starting instrumentation ComponentInfo{com.jayway.test/android.test.InstrumentationTestRunner} from pid=354, uid=354 not allowed because package com.jayway.test does not have a signature matching the target com.android.settings

  1. Can I somehow make it work with the Android Emulator?
  2. If I compile an Android phone image, how can I use the Android system signature with my application?
+1  A: 

The best way to enable wifi from your application would be to use the WifiManager.

WifiManager wManager = (WifiManager)getSystemService(Context.WIFI_SERVICE);

if(!wManager.isWifiEnabled() && wManager.getWifiState() != WifiManager.WIFI_STATE_ENABLING)
    wManager.setWifiEnabled(true);

Note: You also have to add the following permissions to your manifest

<uses-permission android:name="android.permissions.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permissions.CHANGE_WIFI_STATE" />
Jwsonic
I don't just need to switch on/off WiFi. I need to control Settings application with a Robotium script. In fact I want to simulate user clicks to switch on/off WiFi. This process can be done by using a custom script with monkey tool. Although I would like to use Robotium in order to verify if a Access Point was really found. My primary goal is to make this Robotium script have access over com.android.settings.apk. This will bypass the signature mismatch and will let my Robotium script control this APK.
Michalis