I want to get unique id for SIM (line1number or simserialnumber...) when SMS is received. It works fine for single SIM. Is it possible for multi SIM?
Multiple SIM support was only added to the standard Android API in Android 5.1 (Lollipop_MR1 - API Level 22) - see here. Devices earlier than that with multiple SIMs used customised versions of Android to support multiple SIMs, so there's no standard way to get the information you want as it will work differently on each device.
If you're targeting API Level 22 and above, you can use SubscriptionManager to get the information about different SIMs.
Yes, You can use the SubscriptionManager to get the subscription information.
Also note that we have a Parcelable class for Subscription Information called SubscriptionInfo that has following method relevant to you:
public int getSimSlotIndex ()
public int getSubscriptionId ()
Related
On Android Oreo or lower, WifiManager#getConfiguredNetworks() method was available to list saved network.
I tested this out in Android 10 emulator and it returns a blank list (as mentioned in the docs). Does anyone know whats the alternate?
Official docs
This method was deprecated in API level 29. a) See
WifiNetworkSpecifier.Builder#build() for new mechanism to trigger
connection to a Wi-Fi network. b) See
addNetworkSuggestions(java.util.List),
removeNetworkSuggestions(java.util.List) for new API to add Wi-Fi
networks for consideration when auto-connecting to wifi. Compatibility
Note: For applications targeting Build.VERSION_CODES.Q or above, this
API will return an empty list, except for:
I'm trying to make a network usage monitor app, which shows mobile data usage history to the user. For this I'm using Usage access to get accurate data usage stats from NetworkStatsManager. But this no longer works in Android 10.
I'm using NetworkStatsManager.querySummaryForDevice which requires subscriber Id, which earlier I was able to obtain using TelephonyManager.getSubscriberId.
But the getSubscriberId is now not working in Android 10 as it requires READ_PRIVILEGED_PHONE_STATE which third-party apps cannot have.
Any ideas on how to make it work? I understand the restrictions for getting subscriber Id, but I don't really care about the subscriber Id as long as I get the mobile data usage, for which I have enough permissions.
Try passing null as subscriber ID in the querySummaryForDevice method .. That worked for me
When calling NetworkStatsManager resolve subscriberId as follows:
use null when running on Android versions 10+ (API Level >= 29) devices
on prior versions of Android (API Level < 29) you should still resolve subscriberId (using TelephonyManager)
Here is a sample code that should help:
public static String getSubscriberId() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
return telephonyManager.getSubscriberId();
} else {
return null;
}
}
Worked for me on Android API Level 29 and Android API Level 26 devices.
There's no way at the moment to get the information you want unless your app is a profile or device owner app. You can just use the TrafficStats but you can't use a query and it resets on reboot.
I have implemented the system to connect to wifi networks from my app programmatically, now I want to forget configured WIFI networks programmatically from the application.
I have implemented this into my application already and its been working fine on the Android 5.0 and lower devices (Less then API 22).
For Android 6.0 and the higher device it is not working (Higher and equal then API 23).
Please refer the following code:
val wifiManager = this#SelectWifiSettingsActivity.baseContext!!.getSystemService(android.content.Context.WIFI_SERVICE) as WifiManager
val list = wifiManager.configuredNetworks
for (i in list) {
wifiManager.disableNetwork(i.networkId)
wifiManager.saveConfiguration()
}
I have also referred the following link:
https://stackoverflow.com/a/33075445/9360112
As there are some changes in WIFI configurations in Android 6.0.
Please, help me if anyone has solution for this on Android 6.0 onwards.
First thing is you don't need to use saveConfiguration().
This method was deprecated in API level 26.
There is no need to call this method - addNetwork(WifiConfiguration), updateNetwork(WifiConfiguration) and removeNetwork(int) already persist the configurations automatically.
Secondly, what you're looking for is removeNetwork().
Your code will look like:
val wifiManager = this#SelectWifiSettingsActivity.baseContext!!.getSystemService(android.content.Context.WIFI_SERVICE) as WifiManager
val list = wifiManager.configuredNetworks
for (i in list) {
wifiManager.removeNetwork(i.networkId)
}
Being said that... There are some changes in the Android M APIs for WifiManager.
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.
See Network Changes in Android M
I am looking to read all incomming calls from the calllog and listing them in my app, but I am unable to get SIM info.
I tried using Calllog.calls.PHONE_ACCOUNT_ID, but that seems to work for only single sim devices and not dual-sim.
I see theirs a property Calllog.calls.VIA_NUMBER, but that's only available for API >=24. but I need to support from API 16(Jelly Bean).
Its just a call log program, so I don't need to palace any calls/messages.
Guys I want to know if there are both the sims available and active in android dual sim phones irrespective of the device OS. I have already checked for few links that gives the result if the device is dual sim or not. But what I want to know is if there are two sim's installed in an android device. Please help me with a code snipnnet
Before API 22 you cannot detect if both the sims are present or not, though you can only check for single sim presence with TelephonyManager class in Android check more on DOCS and here is code snippet as well from similar answered SO question
From Android API 22
getActiveSubscriptionInfoList will get the SubscriptionInfo(s) of the currently inserted SIM(s). The records will be sorted by getSimSlotIndex() then by getSubscriptionId(). as mentioned on Android Docs
Since api 22 there is getActiveSubscriptionInfoList() method you can call.