Rehum
Rehum

Reputation: 600

How can I load an angular 12 app into an Android app via webview?

I have an Angular app available on the web.

For a mobile app (Android) of the web app, we want to load the web app into a webview.

This is the code:

activity_code.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
         >

    <TextView
        android:id="@+id/hello_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="........... Loading ..." />

</LinearLayout>

webview.xml

<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />

MainActivity.java

package xx.xxx.xxx;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

public class MainActivity extends Activity {

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

        /** Load Remote Url Directly */
        Intent intent_remoteurl = new Intent(this, WebViewActivity.class);
        startActivity(intent_remoteurl);
    }
}

WebViewActivity.java

package xx.xxxxx.xxxx;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class WebViewActivity  extends Activity {

    private WebView webview;
    private ProductConstant productConstant = new ProductConstant();

    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.webview);

        webview = (WebView) findViewById(R.id.webView1);
        webview.getSettings().setJavaScriptEnabled(true);
        webview.getSettings().setDomStorageEnabled(true);
        webview.getSettings().setAppCacheEnabled(true);
        webview.getSettings().setAllowFileAccess(true);


        /** webview.getSettings().setUseWideViewPort(true);
        webview.getSettings().setLoadWithOverviewMode(true); */

        webview.loadUrl(productConstant.CONST_FRONTEND_ROOT_PATH);
    }

}

What is wrong?

When running, the app gets stuck on a white screen.

The logcat in Android Studio (the repetitive part):

2021-09-27 01:46:00.995 15970-16003/xx.xxxx.xxxxD/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 0 0
2021-09-27 01:46:01.096 15970-16003/xx.xxxx.xxxxE/eglCodecCommon: glUtilsParamSize: unknow param 0x000085b5
2021-09-27 01:46:01.096 15970-16003/xx.xxxx.xxxxE/eglCodecCommon: glUtilsParamSize: unknow param 0x000085b5
2021-09-27 01:46:01.097 15970-16003/xx.xxxx.xxxx D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 0 0
2021-09-27 01:46:01.099 15970-16003/xx.xxxx.xxxxED/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 0 0
2021-09-27 01:46:01.197 15970-16003/xx.xxxx.xxxxEE/eglCodecCommon: glUtilsParamSize: unknow param 0x000085b5
2021-09-27 01:46:01.197 15970-16003/xx.xxxx.xxxxEE/eglCodecCommon: glUtilsParamSize: unknow param 0x000085b5
....

Upvotes: 1

Views: 3547

Answers (1)

Rehum
Rehum

Reputation: 600

I added this piece of code into WebViewActivity

webview.setWebViewClient(new WebViewClient());

And it works like a charm. Thanks

Upvotes: 2

Related Questions