views:

582

answers:

2

I'm writing an application for android. My problem is that I want it to force the connection in GPRS and not use wi fi. I have a solution like below, but this causes the crash of the application at start.

ConnectivityManager CM = 
    (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
CM.setNetworkPreference(ConnectivityManager.TYPE_MOBILE);

I also added the below setting lines into manifest file.

uses-permission android:name="android.permission.WRITE_SETTINGS" 
uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" 
uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"
uses-permission android:name="android.permission.CHANGE_CONFIGURATION" 
uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" 

Does anyone know the problem, or an answer to set connection type?

+1  A: 

My problem is that I want it to force the connection in GPRS and not use wi fi.

That is not possible in Android today, sorry.

CommonsWare
A: 

What if, if possible, WiFi is disabled?

jege