如果我将Manifest.xml的versionCode从1更改为2,packageInfo.versionCode始终返回1。
我想退货2,我应该在哪里修理?
在这种情况下,packageInfo.versionName偶然返回1.0。

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">

最佳答案

更改

PackageInfo packageInfo=packageManager.getPackageInfo(getContext().getPackageName(), PackageManager.GET_ACTIVITIES);




 PackageInfo packageInfo=packageManager.getPackageInfo(getContext().getPackageName(), 0);

关于android - packageInfo.versionCode始终返回1,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26601345/

10-10 02:28