当前位置: 首页>>代码示例>>Java>>正文


Java Application.getPackageManager方法代码示例

本文整理汇总了Java中android.app.Application.getPackageManager方法的典型用法代码示例。如果您正苦于以下问题:Java Application.getPackageManager方法的具体用法?Java Application.getPackageManager怎么用?Java Application.getPackageManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.app.Application的用法示例。


在下文中一共展示了Application.getPackageManager方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getAppName

import android.app.Application; //导入方法依赖的package包/类
private static String getAppName(Application application, int pID) {
    String processName = null;
    ActivityManager am = (ActivityManager) application.getSystemService(Context.ACTIVITY_SERVICE);
    List l = am.getRunningAppProcesses();
    Iterator i = l.iterator();
    PackageManager pm = application.getPackageManager();
    while (i.hasNext()) {
        ActivityManager.RunningAppProcessInfo info = (ActivityManager.RunningAppProcessInfo) (i.next());
        try {
            if (info.pid == pID) {
                processName = info.processName;
                return processName;
            }
        } catch (Exception e) {
            // Log.d("Process", "Error>> :"+ e.toString());
        }
    }
    return processName;
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:20,代码来源:RApplication.java

示例2: hookPackageManager

import android.app.Application; //导入方法依赖的package包/类
/**
 * hookPackageManager
 *
 * @param application application
 */
private static void hookPackageManager(Application application) {
    try {
        Object currentActivityThread = HookCurrentActivityThread.getCurrentActivityThread(application);
        if (currentActivityThread != null) {
            Field sPackageManagerField = currentActivityThread.getClass().getDeclaredField("sPackageManager");
            sPackageManagerField.setAccessible(true);
            Object sPackageManager = sPackageManagerField.get(currentActivityThread);

            Class<?> iPackageManagerInterface = Class.forName("android.content.pm.IPackageManager");
            Object proxy = Proxy.newProxyInstance(iPackageManagerInterface.getClassLoader(),
                    new Class<?>[]{iPackageManagerInterface},
                    new HookPackageManagerHandler(sPackageManager));

            sPackageManagerField.set(currentActivityThread, proxy);

            PackageManager pm = application.getPackageManager();
            Field mPmField = pm.getClass().getDeclaredField("mPM");
            mPmField.setAccessible(true);
            mPmField.set(pm, proxy);
        }
    } catch (Exception e) {
        ApkLogger.get().debug("hookPackageManager Exception", e);
    }
}
 
开发者ID:LiangMaYong,项目名称:android-apkbox,代码行数:30,代码来源:ApkHook.java

示例3: getFile

import android.app.Application; //导入方法依赖的package包/类
public JarFile getFile(Application app) {
    String packageName = app.getPackageName();
    PackageManager packageManager = app.getPackageManager();
    try {
        PackageInfo packageInfo = packageManager.getPackageInfo(packageName, 0);
        String sourceDir = packageInfo.applicationInfo.sourceDir;
        JarFile apkFile = new JarFile(sourceDir);
        return apkFile;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
开发者ID:dmitrykolesnikovich,项目名称:featurea,代码行数:14,代码来源:ApkFileUtil.java


注:本文中的android.app.Application.getPackageManager方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。