File tree Expand file tree Collapse file tree 3 files changed +26
-13
lines changed
app/src/main/java/com/javiersantos/whatsappbetaupdater Expand file tree Collapse file tree 3 files changed +26
-13
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,10 @@ public class Config {
6
6
public static final String GITHUB_TAGS = GITHUB_URL .concat ("/tags" );
7
7
public static final String GITHUB_APK = GITHUB_URL .concat ("/releases/download/" );
8
8
public static final String WHATSAPP_URL = "http://www.whatsapp.com/android/" ;
9
+ public static final String WHATSAPP_URL_CDN = "https://www.cdn.whatsapp.net/android/" ;
9
10
public static final String WHATSAPP_APK = WHATSAPP_URL .concat ("current/WhatsApp.apk" );
10
11
public static final String PAYPAL_DONATION =
"[email protected] " ;
11
12
13
+ public static final String PATTERN_LATEST_VERSION = "<a class=\" button\" href=\" " ;
14
+
12
15
}
Original file line number Diff line number Diff line change 4
4
import android .app .PendingIntent ;
5
5
import android .content .Context ;
6
6
import android .content .Intent ;
7
+ import android .net .Uri ;
7
8
import android .os .SystemClock ;
8
9
9
10
import com .javiersantos .whatsappbetaupdater .Config ;
@@ -93,4 +94,19 @@ private static Integer getHoursToMilliseconds(Integer hours) {
93
94
return hours * 60 * 60 * 1000 ;
94
95
}
95
96
97
+ public static String getVersionFromString (String s ) {
98
+ String res = "0.0.0.0" ;
99
+
100
+ Uri uri = Uri .parse (s );
101
+ String withoutHost = uri .getPath ();
102
+ String [] split = withoutHost .split ("/" );
103
+ String version = split [2 ];
104
+
105
+ if (!version .equals ("current" )) {
106
+ res = version ;
107
+ }
108
+
109
+ return res ;
110
+ }
111
+
96
112
}
Original file line number Diff line number Diff line change @@ -314,15 +314,17 @@ public static String getLatestWhatsAppVersion() {
314
314
315
315
try {
316
316
HttpClient client = new DefaultHttpClient ();
317
- HttpGet request = new HttpGet (Config .WHATSAPP_URL );
317
+ HttpGet request = new HttpGet (Config .WHATSAPP_URL_CDN );
318
318
HttpResponse response = client .execute (request );
319
319
320
320
InputStream in = response .getEntity ().getContent ();
321
321
BufferedReader reader = new BufferedReader (new InputStreamReader (in ));
322
322
StringBuilder str = new StringBuilder ();
323
323
String line ;
324
324
while ((line = reader .readLine ()) != null ) {
325
- str .append (line );
325
+ if (line .contains (Config .PATTERN_LATEST_VERSION )) {
326
+ str .append (line );
327
+ }
326
328
}
327
329
328
330
in .close ();
@@ -332,18 +334,10 @@ public static String getLatestWhatsAppVersion() {
332
334
e .printStackTrace ();
333
335
}
334
336
335
- String [] split = source .split (">" );
336
- int i = 0 ;
337
- while (i < split .length ) {
338
- if (split [i ].startsWith ("Version" )) {
339
- split = split [i ].split ("( )|(<)" );
340
- res = split [1 ].trim ();
341
- break ;
342
- }
343
- i ++;
344
- }
337
+ String [] split = source .split (Config .PATTERN_LATEST_VERSION );
338
+ String urlWithVersion = split [1 ].split ("\" " )[0 ];
345
339
346
- return res ;
340
+ return UtilsApp . getVersionFromString ( urlWithVersion ) ;
347
341
}
348
342
349
343
public static String getLatestAppVersion () {
You can’t perform that action at this time.
0 commit comments