whether app can Launch the main activity. - Android Activity

Android examples for Activity:Activity Feature

Description

whether app can Launch the main activity.

Demo Code


//package com.java2s;
import android.content.Context;
import android.content.Intent;

import android.content.pm.PackageManager;

import android.text.TextUtils;

public class Main {
    /**/*from  www  .j a  v a2s .  c om*/
     * whether app can Launch the main activity.
     * Return true when can Launch,otherwise return false.
     * @param context
     * @param packageName
     * @return
     */
    public static boolean appCanLaunchTheMainActivity(Context context,
            String packageName) {
        boolean canLaunchTheMainActivity = false;
        do {
            if ((null == context) || TextUtils.isEmpty(packageName)) {
                break;
            }

            PackageManager pm = context.getPackageManager();
            Intent intent = pm.getLaunchIntentForPackage(packageName);
            canLaunchTheMainActivity = (null == intent) ? (false) : (true);
        } while (false);

        return canLaunchTheMainActivity;
    }
}

Related Tutorials