No parts of my website with webview on Android are displayed

0

I am completely new and I am trying to make a webview in Android Studio that shows my web. Everything works correctly except a part of the web that is shown in white and I can not find out why. The problem is not in the web because using app geyser (a generator of online apps) generates an app in which the whole web is seen without problems. The web is librevoz.com and what it does not show me is the content of the courses that are generated in java through Learnpress (a Wordpress plugin). The support for java is correctly enabled since many parts of the web that are made in java are shown. To check this you can access the initiation course to the song and enter the lesson "trust your voice believe in you" that is open to see without registering. Thank you very much for your time!

The code I'm using is this:

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.librevoz.librevoz4">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>


    </application>
    <uses-permission android:name="android.permission.INTERNET" />



</manifest>

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.librevoz.librevoz4.MainActivity">


    <WebView
        android:id="@+id/activity_main_webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</android.support.constraint.ConstraintLayout>

Main.Activity.java

package com.librevoz.librevoz4;

import android.annotation.SuppressLint;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends AppCompatActivity {

    private WebView mWebView;

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

        mWebView = (WebView) findViewById(R.id.activity_main_webview);

        // Enable Javascript
       WebSettings webSettings = mWebView.getSettings();
       webSettings.setJavaScriptEnabled(true);
       mWebView.setWebChromeClient(new WebChromeClient());

        mWebView.loadUrl("https://librevoz.com/");

        // Force links and redirects to open in the WebView instead of in a browser
        mWebView.setWebViewClient(new WebViewClient());

        // Stop local links and redirects from opening in browser instead of WebView
        mWebView.setWebViewClient(new MyAppWebViewClient());
    }

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

MyappwebCLient.java

package com.librevoz.librevoz4;

import android.content.Intent;
import android.net.Uri;
import android.webkit.WebView;
import android.webkit.WebViewClient;

/**
 * Created by vegas on 27/10/2017.
 */

public class MyAppWebViewClient extends WebViewClient {

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if(Uri.parse(url).getHost().endsWith("librevoz.com")) {
            return false;
        }

        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        view.getContext().startActivity(intent);
        return true;
    }
}

styles.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

</resources>
    
asked by Javier Vegas Serrano 28.10.2017 в 10:20
source

1 answer

0

THE PROBLEM IS THAT IT IS INFRINGING THE CONTENT OF THE LESSONS, TRYING TO HAVE THE CODE OF THIS PART SO

// INI AGREGADO         mWebView = (WebView) findViewById (R.id.activity_main_webview);

    // Activamos Javascript
    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setDomStorageEnabled(true);


    mWebView.getSettings().setJavaScriptEnabled(true);
    // Url que carga la app (webview)
    mWebView.loadUrl("https://AQUI LA URL DE TU WEB.com");

    // Forzamos el webview para que abra los enlaces internos dentro de la la APP
    mWebView.setWebViewClient(new WebViewClient());
    mWebView.setWebChromeClient(new WebChromeClient());

    // Forzamos el webview para que abra los enlaces externos en el navegador
    mWebView.setWebViewClient(new MyAppWebViewClient());
    // FIN AGREGADO
}
    
answered by 31.10.2017 / 11:11
source