2.2.25
parent
15f478d592
commit
e0ea540716
Binary file not shown.
Binary file not shown.
@ -1,30 +0,0 @@
|
||||
package com.rehome.zhdcoa.receiver;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class NetworkStatusReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
ConnectivityManager manager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo mobileInfo = manager .getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
|
||||
NetworkInfo wifiInfo = manager .getNetworkInfo(ConnectivityManager.TYPE_WIFI);
|
||||
NetworkInfo activeInfo = manager.getActiveNetworkInfo();
|
||||
if (activeInfo==null) {
|
||||
Toast.makeText( context, "当前网络不可用,请检查网络", Toast.LENGTH_SHORT) .show();
|
||||
}else {
|
||||
if (activeInfo.getTypeName().equals("mobile")) {
|
||||
Toast.makeText( context, "mobile:" + mobileInfo.isConnected() +
|
||||
"\nactive:" + activeInfo.getTypeName(), Toast.LENGTH_SHORT) .show();
|
||||
}
|
||||
if (activeInfo.getTypeName().equals("wifi")) {
|
||||
Toast.makeText( context, "wifi:" + wifiInfo.isConnected() +
|
||||
"\nactive:" + activeInfo.getTypeName(), Toast.LENGTH_SHORT) .show();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,89 @@
|
||||
package com.rehome.zhdcoa.ui.activity
|
||||
|
||||
import android.app.Activity
|
||||
import android.util.Log
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.google.android.play.core.appupdate.AppUpdateInfo
|
||||
import com.google.android.play.core.appupdate.AppUpdateManager
|
||||
import com.google.android.play.core.appupdate.AppUpdateManagerFactory
|
||||
import com.google.android.play.core.install.InstallState
|
||||
import com.google.android.play.core.install.InstallStateUpdatedListener
|
||||
import com.google.android.play.core.install.model.AppUpdateType
|
||||
import com.google.android.play.core.install.model.InstallStatus
|
||||
import com.google.android.play.core.install.model.UpdateAvailability
|
||||
import java.lang.Exception
|
||||
|
||||
|
||||
class InAppUpdate(activity: Activity): InstallStateUpdatedListener {
|
||||
var TAG = javaClass.simpleName
|
||||
private var appUpdateManager: AppUpdateManager
|
||||
private var parentActivity: Activity = activity
|
||||
private var currentType = AppUpdateType.FLEXIBLE
|
||||
private var SELF_UPDATE_REQUEST_CODE = 1
|
||||
|
||||
|
||||
init {
|
||||
Log.i(TAG, "init: I100: Init InAppUpdate")
|
||||
appUpdateManager = AppUpdateManagerFactory.create(parentActivity)
|
||||
appUpdateManager.appUpdateInfo.addOnSuccessListener { info->
|
||||
Log.i(TAG, "init: I100: update info $info")
|
||||
if (info.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE){
|
||||
Log.i(TAG, "I100: init: have update available")
|
||||
} else {
|
||||
Log.i(TAG, "I100: init: no update available")
|
||||
}
|
||||
}
|
||||
appUpdateManager.registerListener(this)
|
||||
}
|
||||
private fun startUpdate(info: AppUpdateInfo, type: Int){
|
||||
try {
|
||||
|
||||
appUpdateManager.startUpdateFlowForResult(info,type,parentActivity, SELF_UPDATE_REQUEST_CODE)
|
||||
currentType = type
|
||||
}catch (exception:Exception){
|
||||
Log.i(TAG, exception.message.toString())
|
||||
}
|
||||
}
|
||||
fun onResume(){
|
||||
appUpdateManager.appUpdateInfo.addOnSuccessListener { info->
|
||||
if(currentType == AppUpdateType.FLEXIBLE){
|
||||
if(info.installStatus() == InstallStatus.DOWNLOADED)
|
||||
flexibleUpdateDownloadCompleted()
|
||||
} else if (currentType == AppUpdateType.IMMEDIATE){
|
||||
if(info.updateAvailability() == UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS) {
|
||||
startUpdate(info, AppUpdateType.IMMEDIATE)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fun onActivityResult(requestCode: Int, resultCode: Int){
|
||||
|
||||
if(requestCode == SELF_UPDATE_REQUEST_CODE){
|
||||
if(resultCode != AppCompatActivity.RESULT_OK){
|
||||
Log.i("app","Update flow failed: $resultCode")
|
||||
}
|
||||
}
|
||||
}
|
||||
fun checkForUpdates(){
|
||||
|
||||
}
|
||||
private fun flexibleUpdateDownloadCompleted(){
|
||||
// Snackbar.make(
|
||||
// (parentActivity as MainActivity).binding.appBarMain.coordinatorLayout,
|
||||
// "An app update has just been downloaded. Please restart app.",
|
||||
// Snackbar.LENGTH_INDEFINITE
|
||||
// ).apply {
|
||||
// setAction("RESTART") { appUpdateManager.completeUpdate()}
|
||||
// setActionTextColor(Color.WHITE)
|
||||
// show()
|
||||
// }
|
||||
}
|
||||
fun onDestroy(){
|
||||
appUpdateManager.unregisterListener(this)
|
||||
}
|
||||
override fun onStateUpdate(state: InstallState) {
|
||||
if(state.installStatus() == InstallStatus.DOWNLOADED){
|
||||
flexibleUpdateDownloadCompleted()
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue