質問編集履歴
1
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -27,3 +27,65 @@
|
|
27
27
|
});
|
28
28
|
|
29
29
|
```
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
```Java
|
34
|
+
|
35
|
+
// Creates instance of the manager.
|
36
|
+
|
37
|
+
AppUpdateManager appUpdateManager = AppUpdateManagerFactory.create(context);
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
// Returns an intent object that you use to check for an update.
|
42
|
+
|
43
|
+
Task<AppUpdateInfo> appUpdateInfoTask = appUpdateManager.getAppUpdateInfo();
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
// Checks that the platform will allow the specified type of update.
|
48
|
+
|
49
|
+
appUpdateInfoTask.addOnSuccessListener(appUpdateInfo -> {
|
50
|
+
|
51
|
+
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
|
52
|
+
|
53
|
+
// For a flexible update, use AppUpdateType.FLEXIBLE
|
54
|
+
|
55
|
+
&& appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) {
|
56
|
+
|
57
|
+
// Request the update.
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
// Create a listener to track request state updates.
|
62
|
+
|
63
|
+
InstallStateUpdatedListener listener = state -> {
|
64
|
+
|
65
|
+
// Show module progress, log state, or install the update.
|
66
|
+
|
67
|
+
};
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
// Before starting an update, register a listener for updates.
|
72
|
+
|
73
|
+
appUpdateManager.registerListener(listener);
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
// Start an update.
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
// When status updates are no longer needed, unregister the listener.
|
82
|
+
|
83
|
+
appUpdateManager.unregisterListener(listener);
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
}
|
88
|
+
|
89
|
+
});
|
90
|
+
|
91
|
+
```
|