Quantcast
Channel: Active questions tagged react-native+android - Stack Overflow
Viewing all articles
Browse latest Browse all 28476

in-app update not working Bare Expo, possible onCreate not running and onResume causing Crashes

$
0
0

I am trying to add Android in-app updates feature onto my bare expo apps, however, after trying to add the code in MainActivities.java, the app just load into the app directly without updating even though it is shown that the version is behind.

I believe that onCreate function is not running since the app just loaded into the app directly while the version is behind the one in Google Play Store. However, I am unsure since many other places can be wrong without error messages.

These code are within MainActivity class

 private AppUpdateManager appUpdateManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    AppUpdateManager appUpdateManager = AppUpdateManagerFactory.create(this);
////    Task<AppUpdateInfo> appUpdateInfoTask = appUpdateManager.getAppUpdateInfo();
    appUpdateManager.getAppUpdateInfo().addOnSuccessListener(
                appUpdateInfo -> {
                    if ((appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE)
                            && appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE))
                    {
                        try{
                          appUpdateManager.startUpdateFlowForResult(
                                // Pass the intent that is returned by 'getAppUpdateInfo()'.
                                appUpdateInfo,
                                // Or 'AppUpdateType.FLEXIBLE' for flexible updates.
                                AppUpdateType.IMMEDIATE,
                                // The current activity making the update rFragmentActivityequest.
                                this,
                                // Include a request code to later monitor this update request.
                                123);
                        }catch (IntentSender.SendIntentException e) {
                            e.printStackTrace();
                        }
                    };
                });
    }
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 123) {
      if (resultCode != RESULT_OK) {
//           log("Update flow failed! Result code: " + resultCode);
      }
    }
  }

  @Override
  protected void onResume() {
    super.onResume();
    appUpdateManager
        .getAppUpdateInfo()
        .addOnSuccessListener(
            appUpdateInfo -> {
              // ...
              if (appUpdateInfo.updateAvailability()
                  == UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS) {
                    // If an in-app update is already running, resume the update.
                    try{appUpdateManager.startUpdateFlowForResult(
                      appUpdateInfo,
                      AppUpdateType.IMMEDIATE,
                      this,
                      123);
                    }catch (IntentSender.SendIntentException e) {
                        e.printStackTrace();
                    }
              }
            });
  }

Edit: Forgot to mention, onResume also causes the app to crash, but even if commented out onResume, it still never seems to get to the update.


Viewing all articles
Browse latest Browse all 28476

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>