Detect if new install or updated version (Android app)

前端 未结 8 1120
-上瘾入骨i
-上瘾入骨i 2020-12-24 06:41

I have an app on the Play Store. I want to put a requirement that if users want to use a certain part of the app, they have to invite a friend before being able to do so. Bu

8条回答
  •  忘掉有多难
    2020-12-24 06:45

    We can use broadcast receiver to listen app update.

    Receiver

    class AppUpgradeReceiver : BroadcastReceiver() {
    
      @SuppressLint("UnsafeProtectedBroadcastReceiver")
      override fun onReceive(context: Context?, intent: Intent?) {
        if (context == null) {
            return
        }
        Toast.makeText(context, "Updated to version #${BuildConfig.VERSION_CODE}!", Toast.LENGTH_LONG).show()
      }
    
    }
    

    Manifest

    
    
        
    
    

    It doesn't work while debug. So you have to install to manually.

    1. Increase the versionCode in your app-level build.gradle (so it counts as an update).
    2. Click Build -> Build Bundle(s) / APK(s) -> Build APK(s), and select a debug APK.
    3. Run following command in the terminal of Android Studio:

      adb install -r C:\Repositories\updatelistener\app\build\outputs\apk\debug\app-debug.apk
      

提交回复
热议问题