Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.content.Context;
import android.content.Intent;

import android.content.pm.ResolveInfo;

import android.text.TextUtils;

public class Main {

    public static String getAppMainActivity(Context context, String packageName) {
        if (TextUtils.isEmpty(packageName)) {
            return "";
        }
        final Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        intent.setPackage(packageName);
        final ResolveInfo res = context.getPackageManager().resolveActivity(intent, 0);
        if (res == null || res.activityInfo == null) {
            return "";
        }
        return res.activityInfo.name;
    }
}