I am trying to run this sample code from TutorialPoint but it is always showing toast
Intent launch = getPackageManager().getLaunchIntentForPackage("com.google.android.youtube");
if (launch != null) {
startActivity(launch);
} else {
Toast.makeText(P01.this,
"There is an issue running this code!",
Toast.LENGTH_SHORT).show();
}
Can someone please help with how to rectify it!
After requesting help over here, I searched for something relevant on Stack Overflow and came across this post. I used it to display all packages on my device, but instead, it only listed a handful:
ResolveInfo{f1539ce com.android.settings/.Settings m=0x108000}
ResolveInfo{6fa90ef com.android.vending/.AssetBrowserActivity m=0x108000}
ResolveInfo{8b2b7fc com.android.stk/.mtk.StkLauncherActivityII m=0x108000}
ResolveInfo{10f4e85 com.dsaghicha.uscs407practicals/.MainActivity m=0x108000}
The last one being my app's package. If I run the above code on any one of these packages it will run
Apparently, I am using Android 11 and there is a privacy policy that restricts package visibility on Android 11. Read more Now, how to access the package on Android 11?