本文整理汇总了Java中android.content.pm.PackageManager.NameNotFoundException方法的典型用法代码示例。如果您正苦于以下问题:Java PackageManager.NameNotFoundException方法的具体用法?Java PackageManager.NameNotFoundException怎么用?Java PackageManager.NameNotFoundException使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.pm.PackageManager
的用法示例。
在下文中一共展示了PackageManager.NameNotFoundException方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: appVersionCode
import android.content.pm.PackageManager; //导入方法依赖的package包/类
public static String appVersionCode(Context context) {
PackageManager pm = context.getPackageManager();
PackageInfo pi = null;
try {
pi = pm.getPackageInfo(context.getPackageName(), PackageManager.GET_ACTIVITIES);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
return "unknown";
}
return pi.versionCode + "";
}
示例2: preloadIcon
import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
* Pre-load an icon into the persistent cache.
*
* <P>Queries for a component that does not exist in the package manager
* will be answered by the persistent cache.
*
* @param componentName the icon should be returned for this component
* @param icon the icon to be persisted
* @param dpi the native density of the icon
*/
public void preloadIcon(ComponentName componentName, Bitmap icon, int dpi, String label,
long userSerial, InvariantDeviceProfile idp) {
// TODO rescale to the correct native DPI
try {
PackageManager packageManager = mContext.getPackageManager();
packageManager.getActivityIcon(componentName);
// component is present on the system already, do nothing
return;
} catch (PackageManager.NameNotFoundException e) {
// pass
}
icon = Bitmap.createScaledBitmap(icon, idp.iconBitmapSize, idp.iconBitmapSize, true);
Bitmap lowResIcon = generateLowResIcon(icon, Color.TRANSPARENT);
ContentValues values = newContentValues(icon, lowResIcon, label,
componentName.getPackageName());
values.put(IconDB.COLUMN_COMPONENT, componentName.flattenToString());
values.put(IconDB.COLUMN_USER, userSerial);
mIconDb.insertOrReplace(values);
}
示例3: getAppVersionCode
import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
* 返回app的版本代码.
*
* @param context the context
* @return app version code
*/
public static int getAppVersionCode(Context context) {
// 获取package manager的实例
PackageManager packageManager = context.getPackageManager();
// getPackageName()是你当前类的包名,0代表是获取版本信息
int code = 1;
PackageInfo packInfo;
try {
packInfo = packageManager.getPackageInfo(context.getPackageName(),
0);
code = packInfo.versionCode;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
// Log.i("版本代码:", version);
return code;
}
示例4: isAppInstalled
import android.content.pm.PackageManager; //导入方法依赖的package包/类
private boolean isAppInstalled(String packageName) {
PackageManager pm = getPackageManager();
boolean installed = false;
try {
pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
installed = true;
} catch (PackageManager.NameNotFoundException e) {
installed = false;
}
return installed;
}
示例5: getVersionName
import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
* 获取当前版本
*
* @param context
* @return
*/
public static String getVersionName(Context context) {
PackageManager pManager = context.getPackageManager();
PackageInfo packageInfo = null;
try {
packageInfo = pManager.getPackageInfo(context.getPackageName(), 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return packageInfo.versionName;
}
示例6: isPackageExist
import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
* 当前的包是否存在
*
* @param context
* @param pckName
* @return
*/
public static boolean isPackageExist(Context context, String pckName) {
try {
PackageInfo pckInfo = context.getPackageManager()
.getPackageInfo(pckName, 0);
if (pckInfo != null)
return true;
} catch (PackageManager.NameNotFoundException e) {
Log.e("TDvice", e.getMessage());
}
return false;
}
示例7: isFrameworkPackage
import android.content.pm.PackageManager; //导入方法依赖的package包/类
private boolean isFrameworkPackage(PackageManager packageManager, String packageName) {
if (fakeFramework) {
try {
PackageInfo packageInfo = packageManager.getPackageInfo(packageName, 0);
return isFrameworkPackage(packageManager, packageInfo);
} catch (PackageManager.NameNotFoundException e) {
UILog.w("cannot find " + packageName, e);
return false;
}
} else {
return packageManager.checkSignatures(PACKAGE_FRAMEWORK, packageName) ==
PackageManager.SIGNATURE_MATCH;
}
}
示例8: getAppName
import android.content.pm.PackageManager; //导入方法依赖的package包/类
public static String getAppName(Context context) {
String appName = "";
try {
PackageManager manager = context.getPackageManager();
PackageInfo info = null;
info = manager.getPackageInfo(context.getPackageName(), 0);
appName = info.applicationInfo.loadLabel(manager).toString();
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return appName;
}
示例9: loadPackageName
import android.content.pm.PackageManager; //导入方法依赖的package包/类
private CharSequence loadPackageName(String pkg) {
try {
ApplicationInfo info = mPm.getApplicationInfo(pkg,
PackageManager.GET_UNINSTALLED_PACKAGES);
if (info != null) return mPm.getApplicationLabel(info);
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "Cannot load package name", e);
}
return pkg;
}
示例10: getPermissionGroupInfo
import android.content.pm.PackageManager; //导入方法依赖的package包/类
private PermissionGroupInfo getPermissionGroupInfo(PackageManager packageManager, String group) {
if (TextUtils.isEmpty(group)) {
return null;
}
try {
return packageManager.getPermissionGroupInfo(group, 0);
} catch (PackageManager.NameNotFoundException e) {
UILog.w("Can't find permission group " + group, e);
return null;
}
}
示例11: getAvailableIconPacks
import android.content.pm.PackageManager; //导入方法依赖的package包/类
public HashMap<String, IconPack> getAvailableIconPacks(boolean forceReload)
{
if (iconPacks == null || forceReload)
{
iconPacks = new HashMap<String, IconPack>();
// find apps with intent-filter "com.gau.go.launcherex.theme" and return build the HashMap
PackageManager pm = mContext.getPackageManager();
List<ResolveInfo> adwlauncherthemes = pm.queryIntentActivities(new Intent("org.adw.launcher.THEMES"), PackageManager.GET_META_DATA);
List<ResolveInfo> golauncherthemes = pm.queryIntentActivities(new Intent("com.gau.go.launcherex.theme"), PackageManager.GET_META_DATA);
// merge those lists
List<ResolveInfo> rinfo = new ArrayList<ResolveInfo>(adwlauncherthemes);
rinfo.addAll(golauncherthemes);
for(ResolveInfo ri : rinfo)
{
IconPack ip = new IconPack();
ip.packageName = ri.activityInfo.packageName;
ApplicationInfo ai = null;
try
{
ai = pm.getApplicationInfo(ip.packageName, PackageManager.GET_META_DATA);
ip.name = mContext.getPackageManager().getApplicationLabel(ai).toString();
iconPacks.put(ip.packageName, ip);
}
catch (PackageManager.NameNotFoundException e)
{
// shouldn't happen
e.printStackTrace();
}
}
}
return iconPacks;
}
示例12: getMetaDaApplication
import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
* Read the meta-data information under the application tag
*
* @param context context
* @return Bundle information for metaData under application tag [Bundle]
*/
public static Bundle getMetaDaApplication(Context context) {
try {
ApplicationInfo applicationInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
return applicationInfo.metaData;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return null;
}
示例13: isSystemApp
import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
* 判断App是否是系统应用
*
* @param context 上下文
* @param packageName 包名
* @return {@code true}: 是<br>{@code false}: 否
*/
public static boolean isSystemApp(Context context, String packageName) {
if (DataUtil.isNullString(packageName))
return false;
try {
PackageManager pm = context.getPackageManager();
ApplicationInfo ai = pm.getApplicationInfo(packageName, 0);
return ai != null && (ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
return false;
}
}
示例14: isLinkInstalled
import android.content.pm.PackageManager; //导入方法依赖的package包/类
@Override
public boolean isLinkInstalled(Context context, String packageName) {
PackageInfo packageInfo;
try {
packageInfo = context.getPackageManager().getPackageInfo(packageName, 0);
} catch (PackageManager.NameNotFoundException e) {
packageInfo = null;
e.printStackTrace();
}
if (packageInfo == null) {
return false;
} else {
return true;
}
}
示例15: isPackageInstalled
import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
* 是否安装了该包名的app
*
* @param context context
* @param pkgName 包名
* @return 是否安装
*/
private static boolean isPackageInstalled(Context context, String pkgName) {
PackageManager pm = context.getPackageManager();
try {
PackageInfo pkgInfo = pm.getPackageInfo(pkgName, 0);
return pkgInfo != null && pkgInfo.applicationInfo.enabled;
} catch (PackageManager.NameNotFoundException e) {
}
return false;
}