I just want to ask you if you anyone knows how to change the Setting
available in:
Settings->Wireless Settings->Mobile Network from code or
Setting: Settings->Wireless Settings->Mobile Network Settings->Network
operators->Select Automatically?
I had been unable to find a property that match this setting in the
Settings.System / Settings.Secure classes.
Is there any alternative way to "turn on/off" the MOBILE
connectivity ?
The reason I need to solve this is to workaround the
bug occur during transitioning from WIFI to MOBILE that do not enable
CELL data automatically.
I think support for this sort of thing(changing settings from code) was removed/deprecated in the newer versions of the SDK; it is not advisable. What I've said is based on Dan Morill's Blog titled: Future Proofing your Android Apps
Eitherways, generally, you would write:
Settings.System.putString(getContentResolver(), <Settings.System.CONST>, <value>);
and have the following permission in your maifest: android.permission.WRITE_SETTINGS
The List of Settings.System.CONST can be found in the official documentation: see here
Related
I want Android source code to set preferred network type from my android application.
I can read preferred network by following code.
Settings.Global.getString(context.getContentResolver(),Settings.Global.NETWORK_PREFERENCE)
Because of user privacy and security, apps are not allowed to change the preferred network type
check out this answer: Change mobile network mode (gsm, wcdma, auto)
When you'll scroll the above link, you'll find this answer. But when you'll go to your AndroidStudio and start adding the permissions to your AndroidManifest.xml file, you'll come across this :
Which says that the permission is granted only to the system apps.
I am trying to read the Preferred network type setting from the device. But nowhere android API's are available.
Use case:
Trying to read the Preferred network type and connected network type so that if the device has LTE enabled and the user is forcefully switched back to the lower network(3G,2G); then there should be a notification sent to the user.
I have checked the system setting code, But it's deprecated.
Settings.Secure.getString(getApplicationContext().getContentResolver(),
Settings.System.NETWORK_PREFERENCE);
Is there any alternate way to read the system secured settings(By reflection?).
And Also is it possible to write back the setting with the user permission?
Help is much appreciated.
I think the right code is:
Settings.Global.getString(context.getContentResolver(),Settings.Global.NETWORK_PREFERENCE)
Not able to understand WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN, which is introduced in Android M. .However the definition in android developer site is very ambiguous.Please anyone clarify about this varible
WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN - is the defined user wifi configuration state (true means its locked, false means its changeable).
from android documentation :
http://developer.android.com/reference/android/provider/Settings.Global.html
This setting controls whether WiFi configurations created by a Device
Owner app should be locked down (that is, be editable or removable
only by the Device Owner App, not even by Settings app).
since Marshmallow this configurations have been changed and now are accessible only if you produce your own configuration per application using specific API's.
please refer to Android 6.0 Changes.
https://developer.android.com/about/versions/marshmallow/android-6.0-changes.html
Your apps can now change the state of WifiConfiguration objects only
if you created these objects. You are not permitted to modify or
delete WifiConfiguration objects created by the user or by other apps.
hope it clarifies a bit.
I have found the following code to establish a new vpn programmatically but I do not know how to use it to create my app
VpnService service = context.getSystemService(VPN_SERVICE);
VpnProfile profile = VpnProfile.create(L2TP_PROFILE);
profile.setName(myServerName);
profile.setServerName(myServerAddress);
profile.setRouteList("192.168.1.0/255.255.255.0,192.168.10.0/255.255.255.0");
service.connect(profile, "myUserName", "myPassword");
service.setNotificationIntent(myIntent);
can anyone please help me with a sample code?
Is it even possible to to achieve dis?
Note: this answer is dated and may now be inaccurate.
Take a look at this question: How to configure VPN programmatically?
While yours isn't necessarily a duplicate, the answer is likely the same, in that you're going to need to expose the hidden API (if it's available) or worse, be dependent on the device being rooted.
Understandably, programmatically creating a VPN connection poses an inherent security risk for the end user, and shouldn't be implemented without consideration.
On android 2.3 the permission <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" /> is not allowed anymore for non-system applications. Is there an alternative to enable/disable data connection, besides that one where you modify APN name? I found Data Enabler Widget on Android Market that does that, but I can't seem to understand how. Can anyone help me?
Thanks! - Alex Ady
I don't know how to change data connection (3g, 2g, etc), but you can enable/disable wifi connection through this:
WifiManager wifiManager = (WifiManager)this.getSystemService(Context.WIFI_SERVICE);
wifiManager.setWifiEnabled(boolean enabled);
I found a solution to my problem, so I'm closing this question. The alternative is to simply display the mobile settings activity if a level 10 API or higher is detected, or continue with direct enable from code otherwise. I keep the android.permission.MODIFY_PHONE_STATE, but only use it the API is under level 10.