3

I have a Raspberry Pi running WebIOPi, which is connected to a relay board to turn things on and off via a web-based interface. Here's what the interface looks like in a browser:

enter image description here

Everything works fine, but I want to create an android app that would simply display the web-based interface via WebView. I've used WebView before and it seems pretty straight forward, but I can't get it working.

Here's my code:

MainActivity:

package org.kevinbright.android.backyardcontrolapp; import android.app.Activity; import android.os.Bundle; import android.webkit.WebView; import android.webkit.WebViewClient; public class MainActivity extends Activity { private WebView mWebViewer; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //url = getIntent().getStringExtra(EXTRA_URL); mWebViewer = (WebView)findViewById(R.id.webviewer); mWebViewer.setWebViewClient(new WebViewClient()); mWebViewer.clearCache(true); mWebViewer.getSettings().setJavaScriptEnabled(true); mWebViewer.loadUrl("http://192.168.1.100:8000/"); } } 

Here's the XML:

<?xml version="1.0" encoding="UTF-8"?> <LinearLayout android:orientation="vertical" android:layout_height="match_parent" android:layout_width="match_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <WebView android:layout_height="match_parent" android:layout_width="match_parent" android:id="@+id/webviewer"/> 

And I added:

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

to the Manifest.

I don't get any logcat errors, but when I run the app, I get only a white screen. Also, if I substitute "http://www.google.com", everything works fine. Also, I'm testing on a live device (no emulator). Any suggestions as to why this isn't working?

1
  • that should load if u have all the requisite permissions set on the webView and if used , on the webVwClient... u will need to debug the java up until the webView's load() ... then shift debugger to chrome dev tools Commented Mar 23, 2016 at 2:25

3 Answers 3

1

if you're using http protocol, try to add this on your android manifest

android:usesCleartextTraffic="true" 

it works for me

Sign up to request clarification or add additional context in comments.

1 Comment

This question is from 2016, where this wasn't required.
1
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.webview); mWebView = (WebView)findViewById(R.id.webview); mWebView.clearCache(true); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.loadUrl("http://10.0.2.2:8080/SampleWebServer/Welcome.html"); //pass complete url } 

1 Comment

Please explain why it should be the complete url. That would be nice to clear about whether there is any difference between using browser and WebView in this case.
0

I have a problem like yours. I've achieved load a local IP, but it takes at least 30 seconds, meanwhile white screen as you. It loooks like chromium (webView) try to find the IP on internet, and at the end said: "oh, it's a local ip, let's load". It's quite weird. I keep on waiting for help as well.

1 Comment

Well I've solved my problem. In fact, it wasn't like yours, because I tried to connect with my local server in a local network without internet connection. And my problem was I had an external reference in my stylesheet (@import url("fonts.googleapis.com/css...). This stupid thing takes me a lot of time. I've checked your code, and it's like my code. I can not help you. Luck!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.