當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。