Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;

import java.util.List;

public class Main {
    public static ApplicationInfo findMetaData(Context ctx, String key) {
        PackageManager pm = ctx.getPackageManager();
        try {
            List<PackageInfo> pkgList = pm.getInstalledPackages(0);
            for (PackageInfo info : pkgList) {
                ApplicationInfo appInfo = pm.getApplicationInfo(info.packageName, PackageManager.GET_META_DATA);
                Bundle bd = appInfo.metaData;
                if (bd == null)
                    continue;
                Object obj = bd.get(key);
                if (obj != null) {
                    //                    System.out.println("find it , panme : "+appInfo.packageName);
                    return appInfo;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}