本文整理汇总了Java中android.content.pm.PackageManager.NameNotFoundException.printStackTrace方法的典型用法代码示例。如果您正苦于以下问题:Java NameNotFoundException.printStackTrace方法的具体用法?Java NameNotFoundException.printStackTrace怎么用?Java NameNotFoundException.printStackTrace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.pm.PackageManager.NameNotFoundException
的用法示例。
在下文中一共展示了NameNotFoundException.printStackTrace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAppVersionCode
import android.content.pm.PackageManager.NameNotFoundException; //导入方法依赖的package包/类
public static int getAppVersionCode(Context context) {
if (context != null) {
PackageManager pm = context.getPackageManager();
if (pm != null) {
PackageInfo pi;
try {
pi = pm.getPackageInfo(context.getPackageName(), 0);
if (pi != null) {
return pi.versionCode;
}
} catch (NameNotFoundException e) {
e.printStackTrace();
}
}
}
return -1;
}
示例2: getRegistrationId
import android.content.pm.PackageManager.NameNotFoundException; //导入方法依赖的package包/类
private String getRegistrationId(Context context) {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
String registrationId = prefs.getString(PROPERTY_REG_ID, "");
if (registrationId=="") {
Log.i(TAG, "GCM Registration not found in prefs.");
return "";
}
// Check if app was updated; if so, it must clear the registration ID
// since the existing regID is not guaranteed to work with the new
// app version.
String registeredVersion = prefs.getString(FlowzrSyncOptions.PROPERTY_APP_VERSION, "");
String currentVersion;
try {
currentVersion = getApplicationContext().getPackageManager().getPackageInfo(getApplicationContext().getPackageName(), 0).versionName;
if (!registeredVersion.equals(currentVersion)) {
Log.i(TAG, "App version changed.");
return "";
}
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return registrationId;
}
示例3: getMetaData
import android.content.pm.PackageManager.NameNotFoundException; //导入方法依赖的package包/类
public static String getMetaData(Context context, @NonNull String key) {
String metaDataValue = "";
try {
PackageManager packageManager = context.getPackageManager();
if (packageManager != null) {
ApplicationInfo applicationInfo = packageManager.getApplicationInfo(
context.getPackageName(), PackageManager.GET_META_DATA);
if (applicationInfo != null && applicationInfo.metaData != null) {
metaDataValue = applicationInfo.metaData.getString(key);
}
}
} catch (NameNotFoundException e) {
e.printStackTrace();
}
return metaDataValue;
}
示例4: getAppName
import android.content.pm.PackageManager.NameNotFoundException; //导入方法依赖的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;
}
示例5: getPackageInfo
import android.content.pm.PackageManager.NameNotFoundException; //导入方法依赖的package包/类
/**
* 获取指定程序信息
*/
public static android.content.pm.PackageInfo getPackageInfo(Context context, String pkg) {
try {
return context.getPackageManager().getPackageInfo(pkg, 0);
} catch (NameNotFoundException e) {
e.printStackTrace();
}
return null;
}
示例6: getPackageInfo
import android.content.pm.PackageManager.NameNotFoundException; //导入方法依赖的package包/类
/**
* 获取指定程序信息
*/
public static PackageInfo getPackageInfo(Context context, String pkg) {
try {
return context.getPackageManager().getPackageInfo(pkg, 0);
} catch (NameNotFoundException e) {
e.printStackTrace();
}
return null;
}
示例7: getChannel
import android.content.pm.PackageManager.NameNotFoundException; //导入方法依赖的package包/类
public static String getChannel(Context context , String channelKey) {
String msg = null;
try {
ApplicationInfo appInfo = context.getPackageManager() .getApplicationInfo(context.getPackageName(),
PackageManager.GET_META_DATA);
msg=appInfo.metaData.getString(channelKey);
} catch (NameNotFoundException e) {
e.printStackTrace();
}
return msg;
}
示例8: onCreate
import android.content.pm.PackageManager.NameNotFoundException; //导入方法依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
try {
mPackageInfo = getPackageManager().getPackageInfo(
getPackageName(), 0);
ApplicationInfo ai = getApplicationInfo();
CharSequence applicationLabel = getPackageManager().getApplicationLabel(ai);
mNotification = new DownloadNotification(this, applicationLabel);
} catch (NameNotFoundException e) {
e.printStackTrace();
}
}
示例9: initWithApiKey
import android.content.pm.PackageManager.NameNotFoundException; //导入方法依赖的package包/类
private void initWithApiKey(Context context) {
try {
ApplicationInfo appInfo = context.getPackageManager().getApplicationInfo(context
.getPackageName(), 128);
Object leyu_app_id = appInfo.metaData.get("leyu_app_id");
Object leyu_app_key = appInfo.metaData.get("leyu_app_key");
_app_id = String.valueOf(leyu_app_id);
_app_key = String.valueOf(leyu_app_key);
} catch (NameNotFoundException e) {
e.printStackTrace();
this._callback.onFailed(e.getMessage());
}
}
示例10: getAppVersionName
import android.content.pm.PackageManager.NameNotFoundException; //导入方法依赖的package包/类
public static String getAppVersionName(Context context) {
String version = "0";
try {
version = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
} catch (NameNotFoundException e) {
e.printStackTrace();
}
return version;
}
示例11: getText
import android.content.pm.PackageManager.NameNotFoundException; //导入方法依赖的package包/类
@Override
public String getText() {
if (mName == null) {
try {
PackageManager pm = mContext.getPackageManager();
PackageInfo pi = pm.getPackageInfo(mPackage, 0);
mName = (String) pi.applicationInfo.loadLabel(pm);
} catch (NameNotFoundException e) {
e.printStackTrace();
mName = mPackage;
}
}
return mName;
}
示例12: getVersionCode
import android.content.pm.PackageManager.NameNotFoundException; //导入方法依赖的package包/类
/**
* 获取APP版本号
*
* @param context
* @return
*/
public static int getVersionCode(Context context) {
int verCode = -1;
try {
verCode = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode;
} catch (NameNotFoundException e) {
e.printStackTrace();
}
return verCode;
}
示例13: loadVersionInfo
import android.content.pm.PackageManager.NameNotFoundException; //导入方法依赖的package包/类
private static final void loadVersionInfo(Context context) {
try {
PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
if (pi != null) {
versionCode = pi.versionCode;
versionName = pi.versionName;
}
} catch (NameNotFoundException e) {
e.printStackTrace();
}
}
示例14: isSystemApplication
import android.content.pm.PackageManager.NameNotFoundException; //导入方法依赖的package包/类
/**
* whether packageName is system application
*
* @param packageManager
* @param packageName
* @return <ul>
* <li>if packageManager is null, return false</li>
* <li>if package name is null or is empty, return false</li>
* <li>if package name not exit, return false</li>
* <li>if package name exit, but not system app, return false</li>
* <li>else return true</li>
* </ul>
*/
public static boolean isSystemApplication(PackageManager packageManager, String packageName) {
if (packageManager == null || packageName == null || packageName.length() == 0) {
return false;
}
try {
ApplicationInfo app = packageManager.getApplicationInfo(packageName, 0);
return (app != null && (app.flags & ApplicationInfo.FLAG_SYSTEM) > 0);
} catch (NameNotFoundException e) {
e.printStackTrace();
}
return false;
}
示例15: getClientVersionName
import android.content.pm.PackageManager.NameNotFoundException; //导入方法依赖的package包/类
public static String getClientVersionName(Context context) {
if (context == null) {
return "";
}
try {
return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
} catch (NameNotFoundException e) {
e.printStackTrace();
return "";
}
}