-
Notifications
You must be signed in to change notification settings - Fork 53
/
MainActivity.java
72 lines (58 loc) · 2.88 KB
/
MainActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package com.zanojmobiapps.inappupdatedemoapp;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import com.sanojpunchihewa.updatemanager.BuildConfig;
import com.sanojpunchihewa.updatemanager.UpdateManager;
import com.sanojpunchihewa.updatemanager.UpdateManager.FlexibleUpdateDownloadListener;
import com.sanojpunchihewa.updatemanager.UpdateManager.UpdateInfoListener;
import com.sanojpunchihewa.updatemanager.UpdateManagerConstant;
public class MainActivity extends AppCompatActivity {
// Declare the UpdateManager
UpdateManager mUpdateManager;
TextView txtFlexibleUpdateProgress;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView txtCurrentVersion = findViewById(R.id.txt_current_version);
TextView txtAvailableVersion = findViewById(R.id.txt_available_version);
TextView txtStalenessDays = findViewById(R.id.txt_staleness_days);
txtFlexibleUpdateProgress = findViewById(R.id.txt_flexible_progress);
txtCurrentVersion.setText(String.valueOf(BuildConfig.VERSION_CODE));
// Initialize the Update Manager with the Activity and the Update Mode
mUpdateManager = UpdateManager.Builder(this);
// Callback from UpdateInfoListener
// You can get the available version code of the apk in Google Play
// Number of days passed since the user was notified of an update through the Google Play
mUpdateManager.addUpdateInfoListener(new UpdateInfoListener() {
@Override
public void onReceiveVersionCode(final int code) {
txtAvailableVersion.setText(String.valueOf(code));
}
@Override
public void onReceiveStalenessDays(final int days) {
txtStalenessDays.setText(String.valueOf(days));
}
});
// Callback from Flexible Update Progress
// This is only available for Flexible mode
// Find more from https://developer.android.com/guide/playcore/in-app-updates#monitor_flexible
mUpdateManager.addFlexibleUpdateDownloadListener(new FlexibleUpdateDownloadListener() {
@Override
public void onDownloadProgress(final long bytesDownloaded, final long totalBytes) {
txtFlexibleUpdateProgress.setText("Downloading: " + bytesDownloaded + " / " + totalBytes);
}
});
}
public void callFlexibleUpdate(View view) {
// Start a Flexible Update
mUpdateManager.mode(UpdateManagerConstant.FLEXIBLE).start();
txtFlexibleUpdateProgress.setVisibility(View.VISIBLE);
}
public void callImmediateUpdate(View view) {
// Start a Immediate Update
mUpdateManager.mode(UpdateManagerConstant.IMMEDIATE).start();
}
}