i have this method which is in my main activity, but i want to use it in other classes, how can i write it into its own class so it can be called when ever? i have tried to make a java class called isCallable with a constructor called the same but im getting lost with what to put in the constructor thanks for any help
private boolean isCallable(Intent intent) {
if (intent == null) {
return false;
}
List<ResolveInfo> list = getPackageManager().queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY);
return list.size() > 0;
}
Step #1: Create a Java class named HarropUtils
.
Step #2: Implement the following static
method on HarropUtils
static boolean isCallable(Context ctxt, Intent intent) {
if (intent == null) {
return false;
}
List<ResolveInfo> list = ctxt.getPackageManager().queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY);
return list.size() > 0;
}
Step #3: Call HarropUtils.isCallble()
from wherever you need it, passing in a Context
(e.g., an Activity
) and the Intent
to test.