Check if Activity exist - Android android.app

Android examples for android.app:Activity

Description

Check if Activity exist

Demo Code

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager;
import android.content.res.Resources;

public class Main{

  
    public static boolean hasActivity(Context context, String pkg,
            String cls) {/*from   w w  w  . j ava2 s.  c  o  m*/
        boolean has = true;
        Intent intent = new Intent();
        intent.setClassName(pkg, cls);
        if (context.getPackageManager().resolveActivity(intent, 0) == null) {

            has = false;
        }
        return has;
    }

}

Related Tutorials