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)
Related
I want to get the PCI of both primary serving cell and secondary serving cell in 5G NSA, but it seems that I cannot get what I want using getAllCellInfo(). It seems that I need to parse the physical channel configuration as below:
{{mConnectionStatus=PrimaryServing,...,mRat=LTE,...,mPhysicalCellId=123},
{mConnectionStatus=SecondaryServing,...,mRat=NR,...}
Does anyone know how to get the (real-time) configuration? Or can I get the PCIs in another way? Thanks very much!
About PhysicalChannelConfig
The only possible way how to obtain PhysicalChannelConfig is via TelephonyManager.registerTelephonyCallback method. You can for example pass an instance of TelephonyCallback.PhysicalChannelConfigListener and you'll start obtaining what you need.
Please note that permission Manifest.permission.READ_PRECISE_PHONE_STATE is required, so your app needs to be a system app of carrier-privileged app.
There were some attempts to adjust this protection level, current status can be seen here. But as of Android 12 there's no way how to get PhysicalChannelConfig if you are a regular developer.
About PCIs
You can sometimes get PCIs of serving LTE and NR NSA cells via getAllCellInfo() as you mentioned. Sometimes there's one instance of CellInfoNr with PCI is present. This behaviour is device-specific.
Generally speaking - Android does not provide any official API you request.
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.
So I've research this subject and I didn't get much information, even though I did read a few threads here like Check SIM PIN with SDK Android and Ask user for SIM Card PIN but neither of them really answer the question - the app I'm trying to write is based on USSD and will run on devices with SIMCards.
I also read the thread Use system PIN dialog in Android application, but I'm not trying to overwrite the OS, I'm just trying to write a simple app that can check an entered String against the SIMCard PIN. On this last thread, a user (a.ch.) said that trying to access or even check the SIMCard PIN number is not allowed by the OS (at least without modifications, I suppose). Can you guys confirm or give me a link that mentions this prohibition?
Also, is it possible to, using only USSD, check the PIN? For example, I only know the MMI code to change PIN:
**04*Current PIN * New PIN * New PIN#.
And this actually returns fail or sucess messages, and if I make Current PIN = New PIN, I can actually identify if the PIN I introduced is correct or not, but I see this on a text message. Does the smartphone return this info in a attribute that I can check? How can I access the return code?
I need all the help I can get :)
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.
Is it possible to enable or disable HSDPA connection programatically in Android?
If so, how to do that? I didn't find any API in TelephonyManager.
It is not possible to enable Network(CDMA, 3G or HSDPS) programmatically as of now. As we know we can enable WiFi programatically.
But we can set the preferable network among Mobile / WiFi.
ConnectionManager.setNetworkPreference(ConnectionManager.TYPE_MOBILE/TYPE_WIFI);
Unfortunately, it is not working for me. When I tried to set TYPE_MOBILE, I am getting Security Exception even if I had required permission in my manifest.
When I tried to set TYPE_WIFI, It is not throwing exception, but while getting network preference, I am getting "-1", means there is no preferred network(No Documentation, its my prediction).