Skip to content

Commit

Permalink
Added user agent for APKMirror requests.
Browse files Browse the repository at this point in the history
  • Loading branch information
rumboalla committed Feb 17, 2017
1 parent 63a7dae commit 379b4ef
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected UpdaterStatus parseUrl(
String url
) {
try {
Document doc = Jsoup.connect(url).get();
Document doc = Jsoup.connect(url).userAgent(VersionUtil.getUserAgent(mContext)).get();

// Check if no results
Elements elements = doc.getElementsByClass("addpadding");
Expand Down
23 changes: 23 additions & 0 deletions app/src/main/java/com/apkupdater/util/VersionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

import android.content.Context;
import android.content.pm.PackageInfo;

import com.apkupdater.R;

import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -68,6 +73,24 @@ static public boolean isExperimental(
) {
return s.toLowerCase().contains("beta") || s.toLowerCase().contains("alpha");
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

static public String getUserAgent(
Context context
) {
String version = "0.0.0";
try {
PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
version = pInfo.versionName;
} catch (Exception ignored) {

}

return context.getString(R.string.app_name) + "-v" + version;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

0 comments on commit 379b4ef

Please sign in to comment.