本文整理汇总了Java中android.content.pm.PackageManager.getPackagesForUid方法的典型用法代码示例。如果您正苦于以下问题:Java PackageManager.getPackagesForUid方法的具体用法?Java PackageManager.getPackagesForUid怎么用?Java PackageManager.getPackagesForUid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.pm.PackageManager
的用法示例。
在下文中一共展示了PackageManager.getPackagesForUid方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findPackageInfo
import android.content.pm.PackageManager; //导入方法依赖的package包/类
private static PackageInfo findPackageInfo(PackageManager pm, String pkg, int uid) {
final String[] packages = pm.getPackagesForUid(uid);
if (packages != null && pkg != null) {
final int N = packages.length;
for (int i = 0; i < N; i++) {
final String p = packages[i];
if (pkg.equals(p)) {
try {
return pm.getPackageInfo(pkg, PackageManager.GET_SIGNATURES);
} catch (NameNotFoundException e) {
Log.w(TAG, "Failed to load package " + pkg, e);
}
}
}
}
return null;
}
示例2: hasInternet
import android.content.pm.PackageManager; //导入方法依赖的package包/类
public static boolean hasInternet(int uid, Context context) {
PackageManager pm = context.getPackageManager();
String[] pkgs = pm.getPackagesForUid(uid);
if (pkgs != null)
for (String pkg : pkgs)
if (hasInternet(pkg, context))
return true;
return false;
}
示例3: getApplicationNames
import android.content.pm.PackageManager; //导入方法依赖的package包/类
public static List<String> getApplicationNames(int uid, Context context) {
List<String> listResult = new ArrayList<>();
if (uid == 0)
listResult.add(context.getString(R.string.title_root));
else if (uid == 1013)
listResult.add(context.getString(R.string.title_mediaserver));
else if (uid == 9999)
listResult.add(context.getString(R.string.title_nobody));
else {
PackageManager pm = context.getPackageManager();
String[] pkgs = pm.getPackagesForUid(uid);
if (pkgs == null)
listResult.add(Integer.toString(uid));
else
for (String pkg : pkgs)
try {
ApplicationInfo info = pm.getApplicationInfo(pkg, 0);
listResult.add(pm.getApplicationLabel(info).toString());
} catch (PackageManager.NameNotFoundException ignored) {
}
Collections.sort(listResult);
}
return listResult;
}
示例4: isSystem
import android.content.pm.PackageManager; //导入方法依赖的package包/类
public static boolean isSystem(int uid, Context context) {
PackageManager pm = context.getPackageManager();
String[] pkgs = pm.getPackagesForUid(uid);
if (pkgs != null)
for (String pkg : pkgs)
if (isSystem(pkg, context))
return true;
return false;
}
示例5: isGapps
import android.content.pm.PackageManager; //导入方法依赖的package包/类
private static boolean isGapps(PackageManager pm, int callingUid) {
String[] packageNames = pm.getPackagesForUid(callingUid);
if (packageNames == null) {
return false;
}
for (String packageName : packageNames) {
if (isGapps(packageName)) {
return true;
}
}
return false;
}
示例6: ApplicationInfoEx
import android.content.pm.PackageManager; //导入方法依赖的package包/类
public ApplicationInfoEx(Context context, int uid) {
mUid = uid;
mMapAppInfo = new TreeMap<String, ApplicationInfo>();
PackageManager pm = context.getPackageManager();
String[] packages = pm.getPackagesForUid(uid);
if (packages != null)
for (String packageName : packages)
try {
ApplicationInfo appInfo = pm.getApplicationInfo(packageName, 0);
mMapAppInfo.put(pm.getApplicationLabel(appInfo).toString(), appInfo);
} catch (NameNotFoundException ignored) {
}
}
示例7: getCallingPackages
import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
* Gets the calling package names for the current transaction.
* @param context The context to use for accessing the package manager.
* @return The calling package names.
*/
private static String[] getCallingPackages(Context context) {
int callingUid = Binder.getCallingUid();
PackageManager pm = context.getApplicationContext().getPackageManager();
return pm.getPackagesForUid(callingUid);
}
示例8: getPackageName
import android.content.pm.PackageManager; //导入方法依赖的package包/类
private static String getPackageName(Context context, int uid) {
PackageManager packageManager = context.getPackageManager();
String[] packageList = packageManager.getPackagesForUid(uid);
if (packageList.length != 1 || TextUtils.isEmpty(packageList[0])) return null;
return packageList[0];
}