Android How to - Check if Activity is installed








Question

We would like to know how to check if Activity is installed.

Answer

/*www  .ja  v  a2s.c  om*/
import android.content.Context;
import android.content.Intent;

public class Main {
  public static boolean hasActivity(Context context, String pkg, String cls) {
    boolean has = true;
    Intent intent = new Intent();
    intent.setClassName(pkg, cls);
    if (context.getPackageManager().resolveActivity(intent, 0) == null) {

      has = false;
    }
    return has;
  }
}