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


Java PackageInfo类代码示例

本文整理汇总了Java中android.content.pm.PackageInfo的典型用法代码示例。如果您正苦于以下问题:Java PackageInfo类的具体用法?Java PackageInfo怎么用?Java PackageInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: findPackageInfo

import android.content.pm.PackageInfo; //导入依赖的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;
}
 
开发者ID:ric96,项目名称:lineagex86,代码行数:18,代码来源:AppNotificationSettings.java

示例2: getAppName

import android.content.pm.PackageInfo; //导入依赖的package包/类
/**
 * 获得APP的名称
 *
 * @param context
 * @return
 */
public static String getAppName(Context context) {
    if (context == null) {
        return null;
    }
    try {
        PackageManager packageManager = context.getPackageManager();
        PackageInfo packageInfo = packageManager.getPackageInfo(
                context.getPackageName(), 0);
        int labelRes = packageInfo.applicationInfo.labelRes;
        String appName = context.getResources().getString(labelRes);
        return appName;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:TIIEHenry,项目名称:TIIEHenry-Android-SDK,代码行数:23,代码来源:AppUtils.java

示例3: dumpPhoneInfo

import android.content.pm.PackageInfo; //导入依赖的package包/类
@SuppressWarnings("deprecation")
private void dumpPhoneInfo(PrintWriter pw) throws PackageManager.NameNotFoundException {
    PackageManager pm = mContext.getPackageManager();
    PackageInfo pi = pm.getPackageInfo(mContext.getPackageName(),
            PackageManager.GET_ACTIVITIES);
    pw.print("App Version: ");
    pw.print(pi.versionName);
    pw.print('_');
    pw.println(pi.versionCode);

    /* Android 版本号 */
    pw.print("OS Version: ");
    pw.print(Build.VERSION.RELEASE);
    pw.print('_');
    pw.println(SDK_INT);

    /* 手机制造商 */
    pw.print("Vendor: ");
    pw.println(Build.MODEL);

    /* CPU 架构 */
    pw.print("CPU ABI: ");
    pw.println(Build.CPU_ABI);
}
 
开发者ID:InnoFang,项目名称:Android-Code-Demos,代码行数:25,代码来源:CrashHandler.java

示例4: getConstants

import android.content.pm.PackageInfo; //导入依赖的package包/类
private String getConstants() {
    StringBuilder res = new StringBuilder();

    res.append("Last Device: ").append(lastDeviceDebugString).append('\n');
    res.append("Build.MANUFACTURER: ").append(Build.MANUFACTURER).append('\n');
    res.append("Build.MODEL: ").append(Build.MODEL).append('\n');
    res.append("Build.PRODUCT: ").append(Build.PRODUCT).append('\n');
    res.append("Build.VERSION.SDK_INT: ").append(Build.VERSION.SDK_INT).append('\n');
    res.append("Build.VERSION.RELEASE: ").append(Build.VERSION.RELEASE).append('\n');

    try {
        PackageInfo packageInfo = getContext().getPackageManager().getPackageInfo(getContext().getPackageName(), 0);
        res.append("Driver versionName: ").append(packageInfo.versionName).append('\n');
        res.append("Driver versionCode: ").append(packageInfo.versionCode).append('\n');
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }

    return res.toString();
}
 
开发者ID:martinmarinov,项目名称:AndroidDvbDriver,代码行数:21,代码来源:ExceptionDialog.java

示例5: neededPermissions

import android.content.pm.PackageInfo; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) @NonNull
static String[] neededPermissions(Context context) {
	PackageInfo info = null;
	try {
		info = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_PERMISSIONS);
	} catch (PackageManager.NameNotFoundException e) { /* */ }
	List<String> needed = new ArrayList<>();
	if (info != null &&
		info.requestedPermissions != null &&
		info.requestedPermissionsFlags != null) {
		for (int i = 0; i < info.requestedPermissions.length; i++) {
			int flags = info.requestedPermissionsFlags[i];
			if ((flags & PackageInfo.REQUESTED_PERMISSION_GRANTED) == 0) {
				needed.add(info.requestedPermissions[i]);
			}
		}
	}
	return needed.toArray(new String[needed.size()]);
}
 
开发者ID:sensorberg-dev,项目名称:permission-bitte,代码行数:20,代码来源:PermissionBitteImpl.java

示例6: isOverlayApp

import android.content.pm.PackageInfo; //导入依赖的package包/类
private boolean isOverlayApp(PackageInfo packageInfo) {
	int mask = FLAG_SYSTEM | FLAG_UPDATED_SYSTEM_APP;
	// Ignore system apps
	if ((packageInfo.applicationInfo.flags & mask) != 0) {
		return false;
	}
	// Ignore Play Services, it's effectively a system app
	if (isPlayServices(packageInfo.packageName)) {
		return false;
	}
	// Get permissions
	String[] requestedPermissions = packageInfo.requestedPermissions;
	if (requestedPermissions != null) {
		for (String requestedPermission : requestedPermissions) {
			if (requestedPermission.equals(SYSTEM_ALERT_WINDOW)) {
				return true;
			}
		}
	}
	return false;
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:22,代码来源:ScreenFilterMonitorImpl.java

示例7: setActionBarTitle

import android.content.pm.PackageInfo; //导入依赖的package包/类
protected void setActionBarTitle(){
	if (isRootPage()){
		String pkgName = getPackageName();
		try {
			PackageInfo pkgInfo = getPackageManager().getPackageInfo(pkgName,0);
			CharSequence appLabel = getPackageManager().getApplicationLabel(pkgInfo.applicationInfo);
			getSupportActionBar().setTitle(appLabel.toString());
		} catch (PackageManager.NameNotFoundException e) {
			e.printStackTrace();
		}
		return;
	}
	Class<? extends DUnitGroupInterface> currentGroup = getCurrentGroup();
	ArrayList<DUnitGroupModel> groupModels = DUnitManager.getInstance().getUnitGroupModels();
	for (DUnitGroupModel groupModel: groupModels) {
		if (groupModel.getOriginal() == currentGroup){
			getSupportActionBar().setTitle(groupModel.getName());
			return;
		}
	}
}
 
开发者ID:tik5213,项目名称:DUnit,代码行数:22,代码来源:DUnitSimpleListActivity.java

示例8: startShareApp

import android.content.pm.PackageInfo; //导入依赖的package包/类
public static void startShareApp(Activity activity) {
    try {
        String packageName = activity.getPackageName();
        PackageInfo packageInfo = activity.getPackageManager().getPackageInfo(packageName, 0);
        String dir = packageInfo.applicationInfo.sourceDir;
        File tempFile = new File(dir);

        Intent i = new Intent();
        i.setAction(Intent.ACTION_SEND);
        i.setDataAndType(Uri.fromFile(tempFile), "application/vnd.android.package-archive");
        i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(tempFile));

        // Testing...
        //Only use bluetooth to share the app
        i.setPackage("com.android.bluetooth");
        activity.startActivity(i);
    } catch (Exception e) {
        showLog("SHAREAPP: ", e.getMessage());
    }
}
 
开发者ID:pedromassango,项目名称:Programmers,代码行数:21,代码来源:IntentUtils.java

示例9: AppTarget

import android.content.pm.PackageInfo; //导入依赖的package包/类
private AppTarget(Context context) {
    mContext = context;
    mSharedPreferences = context.getSharedPreferences("va_settings", Context.MODE_MULTI_PROCESS);
    // 从系统已安装的apk中安装插件,默认为false
    fromSystem = mSharedPreferences.getBoolean("fromSystem", false);
    firstInstall = mSharedPreferences.getBoolean("install", false);
    mApkFile = new File(Environment.getExternalStorageDirectory(), "debug.apk").getAbsolutePath();
    mUpdateFile = mApkFile;
    if (!firstInstall) {
        PackageInfo packageInfo = PackageUtils.getPackageInfo(context, PKG);
        // 如果从系统中查找该包名存在,说明系统中已安装过此apk, 则可以从系统中加载此插件.
        if (packageInfo != null) {
            fromSystem = true;
            mApkFile = packageInfo.applicationInfo.publicSourceDir;
        }
    }
}
 
开发者ID:coding-dream,项目名称:TPlayer,代码行数:18,代码来源:AppTarget.java

示例10: call

import android.content.pm.PackageInfo; //导入依赖的package包/类
@Override
public Object call(Object who, Method method, Object... args) throws Throwable {
	int flags = (int) args[0];
	int userId = VUserHandle.myUserId();
	List<PackageInfo> packageInfos;
	if (isAppProcess()) {
		packageInfos = new ArrayList<PackageInfo>(VirtualCore.get().getAppCount());
	} else {
		packageInfos = VirtualCore.get().getUnHookPackageManager().getInstalledPackages(flags);
	}
	packageInfos.addAll(VPackageManager.get().getInstalledPackages(flags, userId));
	if (ParceledListSliceCompat.isReturnParceledListSlice(method)) {
		return ParceledListSliceCompat.create(packageInfos);
	} else {
		return packageInfos;
	}
}
 
开发者ID:codehz,项目名称:container,代码行数:18,代码来源:GetInstalledPackages.java

示例11: isPlayServices

import android.content.pm.PackageInfo; //导入依赖的package包/类
private boolean isPlayServices(String pkg) {
	if (!PLAY_SERVICES_PACKAGE.equals(pkg)) return false;
	try {
		PackageInfo sigs = pm.getPackageInfo(pkg, GET_SIGNATURES);
		// The genuine Play Services app should have a single signature
		Signature[] signatures = sigs.signatures;
		if (signatures == null || signatures.length != 1) return false;
		// Extract the public key from the signature
		CertificateFactory certFactory =
				CertificateFactory.getInstance("X509");
		byte[] signatureBytes = signatures[0].toByteArray();
		InputStream in = new ByteArrayInputStream(signatureBytes);
		X509Certificate cert =
				(X509Certificate) certFactory.generateCertificate(in);
		byte[] publicKeyBytes = cert.getPublicKey().getEncoded();
		String publicKey = StringUtils.toHexString(publicKeyBytes);
		return PLAY_SERVICES_PUBLIC_KEY.equals(publicKey);
	} catch (NameNotFoundException | CertificateException e) {
		if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
		return false;
	}
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:23,代码来源:ScreenFilterMonitorImpl.java

示例12: openAppByPackageName

import android.content.pm.PackageInfo; //导入依赖的package包/类
/**
 * 根据包名打开第三方应用
 *
 * @param context
 * @param packageName
 * @throws PackageManager.NameNotFoundException
 */
public static void openAppByPackageName(Context context, String packageName) throws PackageManager.NameNotFoundException {
    PackageInfo pi;
    try {
        pi = MyApplication.getContext().getPackageManager().getPackageInfo(packageName, 0);
        Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);
        resolveIntent.setPackage(pi.packageName);
        PackageManager pManager = MyApplication.getContext().getPackageManager();
        List<ResolveInfo> apps = pManager.queryIntentActivities(resolveIntent, 0);
        ResolveInfo ri = apps.iterator().next();
        if (ri != null) {
            packageName = ri.activityInfo.packageName;
            String className = ri.activityInfo.name;
            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);//重点是加这个
            ComponentName cn = new ComponentName(packageName, className);
            intent.setComponent(cn);
            context.startActivity(intent);
        }
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
}
 
开发者ID:paradoxie,项目名称:DizzyPassword,代码行数:30,代码来源:MyApplication.java

示例13: getApkInfo

import android.content.pm.PackageInfo; //导入依赖的package包/类
public String getApkInfo(String fileName) {
    try {
        String dexPath = null;
        if (getExternalFilesDir(null) != null) {
            dexPath = new File(getExternalFilesDir(null), fileName).getAbsolutePath();
        } else if (getFilesDir() != null) {
            dexPath = new File(getFilesDir(), fileName).getAbsolutePath();
        }

        PackageManager pm = getPackageManager();
        PackageInfo info = pm.getPackageArchiveInfo(dexPath, 0);

        StringBuilder sb = new StringBuilder();
        sb.append("\n*** Apk info ***\n");
        sb.append("versionCode:" + info.versionCode);
        sb.append("\nversionName:" + info.versionName);
        sb.append("\n*** Apk info ***\n");

        return sb.toString();
    } catch (Exception e) {
        e.printStackTrace();
        return e.toString();
    }
}
 
开发者ID:Catherine22,项目名称:ClassLoader,代码行数:25,代码来源:MainActivity.java

示例14: generatePackageInfo

import android.content.pm.PackageInfo; //导入依赖的package包/类
public static PackageInfo generatePackageInfo(Package p, int flags, long firstInstallTime, long lastUpdateTime) {
    if (API_LEVEL >= M) {
        return PackageParserMarshmallow.generatePackageInfo.call(p, GIDS, flags, firstInstallTime, lastUpdateTime,
                null, sUserState);
    } else if (API_LEVEL >= LOLLIPOP) {
        if (PackageParserLollipop22.generatePackageInfo != null) {
            return PackageParserLollipop22.generatePackageInfo.call(p, GIDS, flags, firstInstallTime, lastUpdateTime,
                    null, sUserState);
        } else {
            return PackageParserLollipop.generatePackageInfo.call(p, GIDS, flags, firstInstallTime, lastUpdateTime,
                    null, sUserState);
        }
    } else if (API_LEVEL >= JELLY_BEAN_MR1) {
        return PackageParserJellyBean17.generatePackageInfo.call(p, GIDS, flags, firstInstallTime, lastUpdateTime,
                null, sUserState);
    } else if (API_LEVEL >= JELLY_BEAN) {
        return PackageParserJellyBean.generatePackageInfo.call(p, GIDS, flags, firstInstallTime, lastUpdateTime,
                null);
    } else {
        return mirror.android.content.pm.PackageParser.generatePackageInfo.call(p, GIDS, flags, firstInstallTime,
                lastUpdateTime);
    }
}
 
开发者ID:coding-dream,项目名称:TPlayer,代码行数:24,代码来源:PackageParserCompat.java

示例15: checkAvailability

import android.content.pm.PackageInfo; //导入依赖的package包/类
/**
 * Check if Font Provider app is available.
 *
 * @param context Context
 * @return code
 *
 * @see FontProviderAvailability#OK
 * @see FontProviderAvailability#NOT_INSTALLED
 * @see FontProviderAvailability#DISABLED
 * @see FontProviderAvailability#VERSION_TOO_LOW
 */
public static @FontProviderAvailability int checkAvailability(Context context) {
    PackageInfo pi = null;
    try {
        pi = context.getPackageManager().getPackageInfo(PACKAGE, 0);
    } catch (PackageManager.NameNotFoundException ignored) {
    }

    if (pi == null) {
        return NOT_INSTALLED;
    }

    if (!pi.applicationInfo.enabled) {
        return DISABLED;
    }

    if (pi.versionCode < MIN_VERSION) {
        return VERSION_TOO_LOW;
    }

    return OK;
}
 
开发者ID:RikkaApps,项目名称:FontProvider,代码行数:33,代码来源:FontProviderClient.java


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