-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChechIsUpdateReady.java
More file actions
56 lines (48 loc) · 1.78 KB
/
ChechIsUpdateReady.java
File metadata and controls
56 lines (48 loc) · 1.78 KB
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
import android.os.AsyncTask;
import android.util.Log;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.IOException;
public class CheckIsUpdateReady extends AsyncTask<Void, String, String> {
String appURL="";
private UrlResponse mUrlResponse;
public CheckIsUpdateReady(String appURL, UrlResponse callback) {
this.appURL=appURL;
mUrlResponse = callback;
}
@Override
protected String doInBackground(Void... voids) {
String newVersion = null;
try {
Document document = Jsoup.connect(appURL)
.timeout(20000)
.userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6")
.referrer("http://www.google.com")
.get();
if (document != null) {
Elements element = document.getElementsContainingOwnText("Current Version");
for (Element ele : element) {
if (ele.siblingElements() != null) {
Elements sibElemets = ele.siblingElements();
for (Element sibElemet : sibElemets) {
newVersion = sibElemet.text();
}
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
return newVersion;
}
@Override
protected void onPostExecute(String onlineVersion) {
super.onPostExecute(onlineVersion);
if (onlineVersion != null && !onlineVersion.isEmpty()) {
mUrlResponse.onReceived(onlineVersion);
}
Log.d("update", " playstore App version " + onlineVersion);
}
}