本文整理匯總了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 "";
}
}