Network ON/OFF

schnibli

New Member
Hello,

Is it possible to turn on/off the data Network?


Edge ON/OFF
HSPA ON/OFF
GPRS ON/OFF

all networks individually turn on / off
 
Last edited:

rbsoft

Active Member
Licensed User
Longtime User
In other words you would like to put the datamode of the device from 3g mode into 2g mode. I would love that too, but I am afraid it is not possible to do that programatically. The apps I found on the playstore all just link to the settings but do not switch by themselves. I would love that functionality too, because in one of my apps I need slow but stable connection.

Rolf
 
Upvote 0

rbsoft

Active Member
Licensed User
Longtime User
...and I guess no way to programaticly switch between 2g and 3g. Thanks for the info, Erel.

Rolf
 
Upvote 0

Shameem

Member
Licensed User
Longtime User
Switching on GPRS with Android 2.3.6 Build is working is fine (Toggle Library) but not with Android 4.1.1 , Is there any one help me to make it work on this .
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use this code with Android 2.3+:
B4X:
Sub SetMobileData(Enabled As Boolean)
   Dim r As Reflector
   r.Target = r.GetContext
   r.Target = r.RunMethod2("getSystemService", "connectivity", "java.lang.String")
   r.Target = r.GetField("mService")
   r.RunMethod2("setMobileDataEnabled", Enabled, "java.lang.boolean")
End Sub

In the manifest editor you should add:
B4X:
AddPermission(android.permission.CHANGE_NETWORK_STATE)

It is based on this solution: http://stackoverflow.com/questions/...a-connection-in-android-programmatically?rq=1
 
Upvote 0

rbsoft

Active Member
Licensed User
Longtime User
Very interesting. Would there be also a way to set specifically to 2g or 3g mode?

Rolf
 
Upvote 0

rbsoft

Active Member
Licensed User
Longtime User
Too bad. Thank you.

Rolf
 
Upvote 0

rbsoft

Active Member
Licensed User
Longtime User
Was just checking this thread on StackOverflow. Mentions a subtype that holds that informtion about the connection type.
http://stackoverflow.com/questions/14520584/check-2g-network

B4X:
        // Check we're on GPRS or EDGE
        final int subType = network.getSubtype();
        return subType == TelephonyManager.NETWORK_TYPE_EDGE
                || subType == TelephonyManager.NETWORK_TYPE_GPRS;

Since there is a function network.getSubtype() could it be that there is also a function network.setSubtype()?

Rolf
 
Upvote 0

rbsoft

Active Member
Licensed User
Longtime User
Thank you very much for the info, Erel.

Rolf
 
Upvote 0

Shameem

Member
Licensed User
Longtime User
Hi Erel It works fine with Android 4.0.4 but I am getting Permission Denial Error for WRITE_SECURE_SETTINGS , in Version 4.1.1 . , I have added permission also for write_Secure_settings too, Please suggest me a way.
 
Upvote 0
Top