How to autoupdate android app without playstore? Like Facebook app or any Contest app

前端 未结 4 991
傲寒
傲寒 2020-12-12 12:16

How do apps update internally automatically without updating from playstore? I mean the internal data of app is changed (via internet) without updating from playstore. For e

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-12 12:29

    https://github.com/bitstadium/HockeySDK-Android/blob/develop/hockeysdk/src/main/java/net/hockeyapp/android/tasks/DownloadFileTask.java#L194 has the perfect and still working implementation on opening a downloaded APK file...

       private fun install(downloadedAPK: File, context: Context) {
            val intent = Intent(Intent.ACTION_INSTALL_PACKAGE)
            intent.setDataAndType(Uri.fromFile(downloadedAPK),
                    "application/vnd.android.package-archive")
            intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
    
            var oldVmPolicy: StrictMode.VmPolicy? = null
    
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                oldVmPolicy = StrictMode.getVmPolicy()
                val policy = StrictMode.VmPolicy.Builder()
                        .penaltyLog()
                        .build()
                StrictMode.setVmPolicy(policy)
            }
    
            context.startActivity(intent)
    
            if (oldVmPolicy != null) {
                StrictMode.setVmPolicy(oldVmPolicy)
            }
        }
    

提交回复
热议问题