tarofess
tarofess

Reputation: 200

packageInfo.versionCode always return 1

If I change Manifest.xml's versionCode from 1 to 2, packageInfo.versionCode always returns 1. I want to return 2, where should I fix? incidentally packageInfo.versionName returns 1.0 in this case.

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

Upvotes: 1

Views: 2458

Answers (2)

Martijn Symaeys
Martijn Symaeys

Reputation: 81

You are probably using gradle. If you are using gradle you should change the version code in gradle.build not in Androidmanifest.xml

Upvotes: 8

Seshu Vinay
Seshu Vinay

Reputation: 13588

Change

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

to

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

Upvotes: 2

Related Questions