本文整理汇总了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;
}
示例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);
}
}
示例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;
}
}