Reputation: 949
I've created a simple android application which loads a webpage using android WebView. But unfortunately the content isn't displaying for the following url:
https://portal.e-idara.com
Also I'm getting the following logcats:
07-27 13:25:23.021 11972-11972/com.eidara E/chromium: [ERROR:filesystem_posix.cc(89)] stat /data/user/0/com.eidara/cache/WebView/Crashpad: No such file or directory (2)
07-27 13:25:23.021 11972-11972/com.eidara E/chromium: [ERROR:filesystem_posix.cc(62)] mkdir /data/user/0/com.eidara/cache/WebView/Crashpad: No such file or directory (2)
07-27 13:25:23.191 11972-11972/com.eidara D/ConnectivityManager: requestNetwork; getAppId(CallingUid) : 10141, CallingPid : 11972
07-27 13:25:23.311 11972-11972/com.eidara D/NETWORK_STATE: AVAIALBLE
07-27 13:25:23.386 11972-12059/com.eidara E/libEGL: validate_display:255 error 3008 (EGL_BAD_DISPLAY)
I've changed the url to http://google.com
and https://facebook.com
and it works fine.
Following is the code snippet for this application. Can anyone please guide me what I'm missing and why the content isn't showing.
MainActivity
package com.eidara;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
import com.eidara.constants.EidaraWebConstants;
import com.eidara.utils.EidaraWebClient;
public class MainActivity extends AppCompatActivity {
private WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if(isNetworkAvailable()) {
Log.d("NETWORK_STATE","AVAIALBLE");
Log.d("DIRECTORY_LOCATION",Environment.getExternalStorageState());
webView = findViewById(R.id.eidara_main_webview);
webView.setWebViewClient(new EidaraWebClient());
// webView.loadUrl(getString(R.string.url));
webView.loadUrl("https://portal.e-idara.com");
}
else
{
Log.d("NETWORK_STATE","UNAVAIALBLE");
}
}
@Override
public void onBackPressed() {
if(webView.canGoBack())
webView.goBack();
else
super.onBackPressed();
}
public boolean isNetworkAvailable(){
ConnectivityManager cm = (ConnectivityManager) getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
return cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnected();
}
}
EidaraWebClient
public class EidaraWebClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
view.getSettings().setJavaScriptEnabled(true);
view.loadUrl(EidaraWebConstants.URL);
//return super.shouldOverrideUrlLoading(view, request);
return true;
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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=".MainActivity">
<WebView
android:id="@+id/eidara_main_webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.eidara">
<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"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
</manifest>
Upvotes: 6
Views: 6267
Reputation: 9306
I had the issue where I was trying to go to a site and just had regular HTTP site. Nothing fancy and I got the same chromium error. Solved it by adding two lines before the load.
webview.settings.javaScriptEnabled = true
webview.settings.useWideViewPort = true
Upvotes: 2