Added option to use generic user agent string

This commit is contained in:
M66B
2021-05-13 18:46:43 +02:00
parent 3a1382aa11
commit f4a52222ce
6 changed files with 65 additions and 2 deletions

View File

@@ -21,6 +21,7 @@ package eu.faircode.email;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
@@ -65,6 +66,7 @@ public class WebViewEx extends WebView implements DownloadListener, View.OnLongC
setOnLongClickListener(this);
WebSettings settings = getSettings();
settings.setUserAgentString(getUserAgent(context, this));
settings.setUseWideViewPort(true);
settings.setLoadWithOverviewMode(overview_mode);
@@ -350,6 +352,26 @@ public class WebViewEx extends WebView implements DownloadListener, View.OnLongC
}
}
static String getUserAgent(Context context, WebView webView) {
// https://developer.chrome.com/docs/multidevice/user-agent/#chrome-for-android
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean generic_ua = prefs.getBoolean("generic_ua", false);
if (generic_ua) {
boolean large = context.getResources().getConfiguration()
.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE);
return (large ? "Mozilla/5.0" : "Mozilla/5.0 (Mobile)");
} else
try {
if (webView == null)
webView = new WebView(context);
return webView.getSettings().getUserAgentString();
} catch (Throwable ex) {
Log.e(ex);
return null;
}
}
interface IWebView {
void onSizeChanged(int w, int h, int ow, int oh);