简体   繁体   中英

unable to fetch the latest version code from firebase

here I'm fetching the latest version of my app from firebase but after updating the value in console this code is not reflecting updated value of my version pls tell me where i'm going wrong

  FirebaseRemoteConfig mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
                //This is default Map
                firebaseDefaultMap = new HashMap<>();
                //Setting the Default Map Value with the current version code
                firebaseDefaultMap.put(VERSION_CODE_KEY, getCurrentVersionCode());
    
                //Setting that default Map to Firebase Remote Config
                mFirebaseRemoteConfig.setDefaultsAsync(firebaseDefaultMap);
    
                mFirebaseRemoteConfig.setConfigSettingsAsync(
                        new FirebaseRemoteConfigSettings.Builder()
                                .setMinimumFetchIntervalInSeconds(0)
                                .build());

here I'm fetching version from firebase remote config

 mFirebaseRemoteConfig.fetch(0).addOnCompleteListener(new OnCompleteListener<Void>() {
                    @Override
                    public void onComplete(@NonNull Task<Void> task) {
                        if (task.isSuccessful()) {
                            //activate most recently fetch config value
                            mFirebaseRemoteConfig.activate().addOnCompleteListener(new OnCompleteListener<Boolean>() {
                                @Override
                                public void onComplete(@NonNull Task<Boolean> task) {
                                    if(task.isSuccessful()){
                                        //calling function to check if new version is available or not
                                        mFirebaseRemoteConfig.activateFetched();
                                        final double latestAppVersion =  mFirebaseRemoteConfig.getDouble(VERSION_CODE_KEY);
                                        Log.d("appversionlatest",String.valueOf(latestAppVersion));
                                        runOnUiThread(new Runnable() {
                                            @Override
                                            public void run() {
                                                checkForUpdate();
                                            }
                                        });
                                    }
                                }
                            });
                        }
                    }
                });

Try this

try{
        String versionName = getPackageManager()
                .getPackageInfo(getPackageName(), 0).versionName;
    } catch (Exception e) {
        e.printStackTrace();
    }

Edit

import <your package name>.BuildConfig;

String verName = BuildConfig.VERSION_NAME;

also, you will get

.DEBUG 
.APPLICATION_ID 
.BUILD_TYPE 
.VERSION_CODE 

These ara present in gradle.build

defaultConfig {
   minSdkVersion 21
   targetSdkVersion 30
   versionCode 1
   versionName "1.0"....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM