Checking for a receiver of an intent before calling startActivity
Function:
public boolean isCallable(Intent intent) {
List<ResolveInfo> list = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
return list.size() > 0;
}
Usage:
final Intent LaunchIntent = getPackageManager().("com.android.vending");
if(isCallable(LaunchIntent)){
startActivity(LaunchIntent);
}else{
Toast t = Toast.makeText(this, "No play store!", Toast.LENGTH_LONG);
t.setGravity(Gravity.CENTER, 0, 0);
t.show();
}
Written by Matt Munday
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Android
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#