K
K
Krasavchik262020-05-03 22:50:01
JavaScript
Krasavchik26, 2020-05-03 22:50:01

Why doesn't downloading files or opening a gallery work on any sites?

And how to make all the scripts inside the browser work? Java script included. But for example, if you download some kind of online chat, then neither attaching a file nor raising the text field when opening the keyboard works, but simply the keyboard overlaps it. All of this works in a real browser. It can be seen that somewhere, something needs to be added. You can even try on this chat https://pubglite.chatbro.com how it works in chrome browser and how it works in android studio.

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.besedka_layout);
if (getSupportActionBar() != null);

web = findViewById(R.id.webView);
WebSettings ws = web.getSettings();
ws.setJavaScriptEnabled(true);
web.loadUrl(" https://pubglite.chatbro.com ");
web.getSettings().setDomStorageEnabled(true);
web.setWebViewClient(new MyWebViewClient());
}

private class MyWebViewClient extends WebViewClient {
@Override public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
return super.shouldOverrideUrlLoading(view, request);
}

@Override public void onPageFinished(WebView view, String url) {
}

@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
}
}

@Override
public void onBackPressed() {
if (web.canGoBack())
web.goBack();
else
super.onBackPressed();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Artemyev, 2020-05-04
@Vitaly48

Googled as android webview html5 features

wv = (WebView) findViewById(R.id.webview);
    WebSettings ws = wv.getSettings();

    ws.setJavaScriptEnabled(true);
    ws.setAllowFileAccess(true);


    if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.ECLAIR) {
        try {
            Log.d(TAG, "Enabling HTML5-Features");
            Method m1 = WebSettings.class.getMethod("setDomStorageEnabled", new Class[]{Boolean.TYPE});
            m1.invoke(ws, Boolean.TRUE);

            Method m2 = WebSettings.class.getMethod("setDatabaseEnabled", new Class[]{Boolean.TYPE});
            m2.invoke(ws, Boolean.TRUE);

            Method m3 = WebSettings.class.getMethod("setDatabasePath", new Class[]{String.class});
            m3.invoke(ws, "/data/data/" + getPackageName() + "/databases/");

            Method m4 = WebSettings.class.getMethod("setAppCacheMaxSize", new Class[]{Long.TYPE});
            m4.invoke(ws, 1024*1024*8);

            Method m5 = WebSettings.class.getMethod("setAppCachePath", new Class[]{String.class});
            m5.invoke(ws, "/data/data/" + getPackageName() + "/cache/");

            Method m6 = WebSettings.class.getMethod("setAppCacheEnabled", new Class[]{Boolean.TYPE});
            m6.invoke(ws, Boolean.TRUE);

            Log.d(TAG, "Enabled HTML5-Features");
        }
        catch (NoSuchMethodException e) {
            Log.e(TAG, "Reflection fail", e);
        }
        catch (InvocationTargetException e) {
            Log.e(TAG, "Reflection fail", e);
        }
        catch (IllegalAccessException e) {
            Log.e(TAG, "Reflection fail", e);
        }
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question