1
如果我将Manifest.xml的versionCode从1更改为2,packageInfo.versionCode总是返回1. 我想返回2,我应该在哪里修复? 偶然packageInfo.versionName在这种情况下返回1.0。packageInfo.versionCode总是返回1
PackageManager packageManager=getContext().getPackageManager();
try{
PackageInfo packageInfo=packageManager.getPackageInfo(getContext().getPackageName(), PackageManager.GET_ACTIVITIES);
DB_VERSION=packageInfo.versionCode;
Log.v("a"," "+packageInfo.versionCode);
Log.v("b"," "+packageInfo.versionName);
}catch (PackageManager.NameNotFoundException e){
e.printStackTrace();
}
的Manifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example"
android:versionCode="2"
android:versionName="1.1">
我改变PackageManager.GET_ACTIVITIES为0,但在的versionCode是logcat中依然1. – tarofess 2014-10-28 05:33:31
是的getContext()。getPackageNAme()给与Manifest相同的软件包? – 2014-10-28 05:39:25
我的Manifest.xml的包与Java文件顶部的包名称中的包相同。如果我的答案的意思是错误的,对不起。 – tarofess 2014-10-28 05:47:42