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.
Related
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 want to read the DeveloperSettings like - Bluetooth HCI snoop capture enabled/disabled.
Does Android provide an API for user applications to read this information. Is there a listener to which user space app can register and get a callback when value of DeveloperSettings change?
AFAIK you can access some of the properties on the Settings using for example :Settings.Secure.getInt(getContentResolver(),Settings.Secure.BLUETOOTH_ON,0);
I'm not sure about all the features available for developers. Also some of them need root to be modified.
I need to be able to toggle the GPS receiver on and off, and WRITE_SECURE_SETTINGS is required to be able to access secure settings. I've searched around quite a bit, and every answer I saw pretty much said that no app outside of the system/firmware can get that permisssion.
However, that is simply untrue. There are several apps on the market that do exactly what I'm trying to (in regards to GPS), but there are a bunch more that have the WRITE_SECURE_SETTINGS permissions. For example:
Extended Controls
SwitchPro
Profile Flow
So, how can this be done?
I need to be able to toggle the GPS receiver on and off
For privacy reasons, if nothing else, enabling or disabling any sort of location-tracking needs to be solely in the hands of the user via trusted applications, not at the request of arbitrary third parties.
So, if you wish to enable and disable GPS, create your own firmware that does what you need and load that firmware on whatever devices you wish. Or, contribute your changes to existing firmware mods (e.g., Cyanogen).
WRITE_SECURE_SETTINGS is required to be able to access secure settings
Correct.
I've searched around quite a bit, and every answer I saw pretty much said that no app outside of the system/firmware can get that permisssion.
Correct.
However, that is simply untrue.
No, it's pretty true.
There are several apps on the market that do exactly what I'm trying to (in regards to GPS)
They found a security loophole. I will take steps to help ensure this hole gets fixed.
but there are a bunch more that have the WRITE_SECURE_SETTINGS permissions
No, there are a bunch who ask for them. You can ask for whatever permission you want. What you ask for is what shows up in these listings. What you get is a different story.
Try this adb command, this will give permission at application run time
adb shell pm grant package android.permission.WRITE_SECURE_SETTINGS
Step to follow:
Connect your device (Make sure USB Debugging enabled)
Execute above adb command
Install apk
It worked for me...
Just this. You can access the widget that every mobile have.
public void ativaGPS() {
LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
Intent intent = new Intent();
intent.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider");
intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
intent.setData(Uri.parse("3"));
sendBroadcast(intent);
}
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