Telephony.Sms.getDefaultSmsPackage(getApplicationContext());
why this returning null in android 11?
Telephony.Sms.getDefaultSmsPackage(getApplicationContext());
why this returning null in android 11?
Using the permission QUERY_ALL_PACKAGES is problematic since you might be required to remove it if your app isn't eligible to use it. This will be effective in March 2022 - see the details here
To query the sms app you can use the method detailed here
I used this solution to query messaging apps and dialer apps and it works fine
<queries>
<intent>
<action android:name="android.intent.action.SENDTO"/>
<data android:scheme="smsto" android:host="*" />
</intent>
<intent>
<action android:name="android.intent.action.DIAL"/>
<data android:scheme="tel" android:host="*" />
</intent>
</queries>
NOTE:
The part about "android.intent.action.DIAL" isn't relevant for checking the SMS app. I needed it to query the default dialer app and I just pasted it here as an example.
SMS query is detailed in the documentation, but the documentation states that this is valid for other intents that aren't listed in the documentation - so this is an example of adding additional intents that you might be interested in...
Today I have also come across this situation and found that from android R we need to declare uses-permission in the AndroidManifeat file.
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />