Android апликация, проблем при използване на webviews

Ticketa

Registered
Привет,
Имам една "апликация", която идея е просто да отваря сайта (той е с добра mobile version).

Обаче открих един проблем, който не намерих решение за него. Когато се опитам да се впиша с Google акаунт, през Логин формата google казва, че апп не е сигурно. И предполагам проблема идва от използването на import android.webkit.WebView;

Някакво предложение как да фиксна проблема? Четох, че ако има "modal" отваряне "може би" ще се решил проблема? Същност как може да стане?

Java:
package com.player.saitacom;


import androidx.appcompat.app.AppCompatActivity;


import android.os.Bundle;


import android.app.Activity;

import android.view.KeyEvent;

import android.view.Window;

import android.webkit.WebResourceRequest;

import android.webkit.WebView;

import android.webkit.WebViewClient;


public class MainActivity extends AppCompatActivity {


    private WebView webView;


    private final String USER_AGENT = "Mozilla/5.0 (Linux; U; Android 4.1.1; Android 4.4; Android 9; en-us; Galaxy Nexus Build/JRO03C; Nexus 4 Build/JOP24G) AppleWebKit/535.19 (KHTML, like Gecko) Version/4.0 Chrome/18.0.1025.166 Mobile Safari/535.19";


    @Override

    protected void onCreate(Bundle savedInstanceState) {


        super.onCreate(savedInstanceState);

        //this.requestWindowFeature(Window.FEATURE_NO_TITLE);

        getSupportActionBar().hide();

        setContentView(R.layout.activity_main);


        CustomWebViewClient client = new CustomWebViewClient(this);


        webView = findViewById(R.id.webView);

        webView.setWebViewClient(client);

        webView.getSettings().setUserAgentString(USER_AGENT);

        webView.getSettings().setJavaScriptEnabled(true);


        webView.loadUrl("https://website.com");

    }


    @Override

    public boolean onKeyDown(int keyCode, KeyEvent event){

        if(keyCode == KeyEvent.KEYCODE_BACK && this.webView.canGoBack()){

            this.webView.goBack();

            return true;

        }

        return super.onKeyDown(keyCode, event);

    }

}


class CustomWebViewClient extends WebViewClient{

    private Activity activity;

    public CustomWebViewClient(Activity activity){

        this.activity = activity;

    }


    @Override

    public boolean shouldOverrideUrlLoading(WebView webView, String url){

        return false;

    }


    @Override

    public boolean shouldOverrideUrlLoading(WebView webView, WebResourceRequest request){

        return false;

    }

}
 

Ticketa

Registered
ЕДИТ: Струва ми се, че намерих решението, обаче пък когато се опитвам да "заредя" youtube видео през сайта, апликацията всякаш "не отчита" натискането т.е. не се стартира видеото.

Някакви предположения, насоки..или направо решение на проблема?

Youtube клиповете ги зареждам в сайта, чрез iframes:
HTML:
<iframe id="my-video_youtube_iframe" allowfullscreen="1" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" title="2022 Akrapovic BMW X5 M - Wild X5M from Renegade Design" src="https://www.youtube.com/embed/WtGzO4_RDTc?controls=0&amp;rel=0&amp;disablekb=1&amp;showinfo=0&amp;modestbranding=0&amp;html5=1&amp;iv_load_policy=3&amp;autoplay=1&amp;end=0&amp;loop=0&amp;playsinline=1&amp;start=0&amp;nocookie=false&amp;enablejsapi=1&amp;origin=https%3A%2F%2Fweb-tourist.net&amp;widgetid=1" style="width: 100%; height: 100%;" width="972" height="546.75" frameborder="0"></iframe>

Java:
package com.player.Tourist;

import androidx.appcompat.app.AppCompatActivity;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;

import android.app.Activity;
import android.os.Message;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.CookieManager;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends AppCompatActivity {

    private Context contextPop;
    private WebView webViewPop;
    private AlertDialog builder;

    private String url = "https://web-tourist.net";

    private WebView webView;
    private String userAgent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        webView = findViewById(R.id.webView);
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // to continue loading a given URL in the current WebView.
                // needed to handle redirects.
                return false;
            }
        });
        webView.loadUrl(url);

        WebSettings webSettings = webView.getSettings();
        // Set User Agent
        userAgent = System.getProperty("http.agent");
        // the upper line sometimes causes "403: disallowed user agent error"
        userAgent = "";
        webSettings.setUserAgentString(userAgent + "Tourist/1.0");

        // Enable Cookies
        CookieManager.getInstance().setAcceptCookie(true);
        if(android.os.Build.VERSION.SDK_INT >= 21)
            CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true);

        // WebView Tweaks
        webSettings.setJavaScriptEnabled(true);
        webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH);
        webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
        webSettings.setAppCacheEnabled(true);
        webSettings.setDomStorageEnabled(true);
        webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
        webSettings.setUseWideViewPort(true);
        webSettings.setSaveFormData(true);
        webSettings.setEnableSmoothTransition(true);
        webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);

        // Handle Popups
        webView.setWebChromeClient(new CustomChromeClient());
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        webSettings.setSupportMultipleWindows(true);
        contextPop = this.getApplicationContext();
    }

    @Override
    public void onBackPressed() {

        if(webView.canGoBack()) {
            webView.goBack();
        }
        else {
            //super.onBackPressed();
            // Terminate the app
            finishAffinity();
            System.exit(0);
        }
    }

    class CustomChromeClient extends WebChromeClient {

        @Override
        public boolean onCreateWindow(WebView view, boolean isDialog,
                                      boolean isUserGesture, Message resultMsg) {

            webViewPop = new WebView(contextPop);
            webViewPop.setWebViewClient(new WebViewClient() {
                @Override
                public boolean shouldOverrideUrlLoading(WebView view, String url) {
                    // to continue loading a given URL in the current WebView.
                    // needed to handle redirects.
                    return false;
                }
            });

            // Enable Cookies
            CookieManager cookieManager = CookieManager.getInstance();
            cookieManager.setAcceptCookie(true);
            if(android.os.Build.VERSION.SDK_INT >= 21) {
                cookieManager.setAcceptThirdPartyCookies(webViewPop, true);
                cookieManager.setAcceptThirdPartyCookies(webView, true);
            }

            WebSettings popSettings = webViewPop.getSettings();
            // WebView tweaks for popups
            webViewPop.setVerticalScrollBarEnabled(false);
            webViewPop.setHorizontalScrollBarEnabled(false);
            popSettings.setJavaScriptEnabled(true);
            popSettings.setSaveFormData(true);
            popSettings.setEnableSmoothTransition(true);
            // Set User Agent
            popSettings.setUserAgentString(userAgent + "Tourist/1.0");
            // to support content re-layout for redirects
            popSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);

            // handle new popups
            webViewPop.setWebChromeClient(new CustomChromeClient());

            // set the WebView as the AlertDialog.Builder’s view
            builder = new AlertDialog.Builder(MainActivity.this, AlertDialog.THEME_DEVICE_DEFAULT_LIGHT).create();
            builder.setTitle("");
            builder.setView(webViewPop);

            builder.setButton("Close", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    webViewPop.destroy();
                    dialog.dismiss();
                }
            });

            builder.show();
            builder.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

            WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
            transport.setWebView(webViewPop);
            resultMsg.sendToTarget();

            return true;
        }

        @Override
        public void onCloseWindow(WebView window) {
            //Toast.makeText(contextPop,"onCloseWindow called",Toast.LENGTH_SHORT).show();
            try {
                webViewPop.destroy();
            } catch (Exception e) {
                Log.d("Webview Destroy Error: ", e.getStackTrace().toString());
            }

            try {
                builder.dismiss();
            } catch (Exception e) {
                Log.d("Builder Dismiss Error: ", e.getStackTrace().toString());
            }

        }
    }
}
 

Горе