Issue
I was trying to open the Notifications Settings screen on a button click in my app but I get an error toast message saying
The app wasn't found in the list of installed apps
I was following the Android training documents and double checked my package name but I'm not sure why I can't get it to work.
val intent = Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS).apply {
putExtra(Settings.EXTRA_APP_PACKAGE, "com.xyz.abc")
putExtra(Settings.EXTRA_CHANNEL_ID, "com.xyz.abc.SomeUniqueString")
}
startActivity(intent)
Solution
Get your package name programatically, no need to write packagename hardcoded. Get like this:
String packageName=getApplicationContext().getPackageName()
You can also check this app is installed or not:
List<PackageInfo> apps = getPackageManager().getInstalledPackages(0);
for(PackageInfo packageInfo:apps){
if(packageInfo.packageName.equals(packageName)){
//app is installed. do whatever you want
}
}
Answered By - Sultan Mahmud
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.