-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathMainActivity.java
62 lines (47 loc) · 1.89 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
package com.kcode.appupdate;
import android.Manifest;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import com.kcode.lib.UpdateWrapper;
import com.kcode.lib.bean.VersionModel;
import com.kcode.lib.log.L;
import com.kcode.lib.net.CheckUpdateTask;
public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity";
private final static String[] permissions = {Manifest.permission.WRITE_EXTERNAL_STORAGE};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void check(View view) {
checkUpdate(0, null);
}
public void checkNow(View view) {
checkUpdate(5 * 60 * 1000, null);
}
public void checkCustoms(View view) {
checkUpdate(0, CustomsUpdateActivity.class);
}
private void checkUpdate(final long time, final Class<? extends FragmentActivity> cls) {
UpdateWrapper.Builder builder = new UpdateWrapper.Builder(getApplicationContext())
.setTime(time)
.setNotificationIcon(R.mipmap.ic_launcher_round)
.setUrl("http://45.78.52.169/app/update.json")
.setIsShowToast(false)
.setIsShowNetworkErrorToast(true)
.setIsShowBackgroundDownload(true)
.setCallback(new CheckUpdateTask.Callback() {
@Override
public void callBack(VersionModel model, boolean hasNewVersion) {
L.d(TAG, "has new version:" + hasNewVersion + ";version info :" + model.getVersionName());
}
});
if (cls != null) {
builder.setCustomsActivity(cls);
}
builder.build().start();
}
}