Does anyone know what's the problem here?
WebView wv = (WebView) findViewById(R.id.webView1);
gives me webView1 cannot be resolved or is not a field, I don't know why. Here's my XML:
<WebView
android:id="#+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
I eventually want this simple line of code to be executed:
wv.loadUrl("http://www.cinicraft.com/pick.html");
Do you have an automatic build you can check? Also, try cleaning the project, that usually fixes these kinds of errors for me.
Related
When WebView got visible it continuously shows [AUX] error. The full error shown as
E/GPUAUX: [AUX]GuiExtAuxCheckAuxPath:663: Null anb
Can anyone please help me to find the cause of this issue?.
Thanks!
step 1:- replace http => https
step2:-
implementation 'com.github.delight-im:Android-AdvancedWebView:v3.2.1'
<im.delight.android.webview.AdvancedWebView
android:id="#+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
The app does not connect to the internet. I have
<uses-permission android:name="android.permission.INTERNET" />
in my manifest and I checked the other applications on the emulator for example youtube and google search works but the application isn't able to load the page. This is my main java file.
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView myWebview ;
myWebview = (WebView) this.findViewById(R.id.webz);
myWebview.loadUrl("https://en.wikipedia.org/");
}
}
and this is my main activity
<?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.example.hoda.myapplication.MainActivity">
<WebView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/webz"></WebView>
</android.support.constraint.ConstraintLayout>
this is the error i get
[ERROR:gl_surface_egl.cc(289)] eglChooseConfig failed with error EGL_SUCCESS
Try enabling javascript and override the webviewclient to avoid redirection:
WebView myWebview ;
myWebview = (WebView) this.findViewById(R.id.webz);
myWebview.getSettings().setJavaScriptEnabled(true);
myWebview.setWebViewClient(new WebViewClient());
myWebview.loadUrl("https://en.wikipedia.org/");
and update the constraints of your WebView:
<WebView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:id="#+id/webz"></WebView>
The problem was with the emulator's graphics I believe as trying #diegoveloper 's solution on the emulator still did not load the page but trying it on an actual android device was successful.
Do this
Restart the emulator (as suggested in another post and in the comments of this post)
If that doesn't work, restart your device.
Worked for me.
Add activity in your AndroidManifest.xml
android:name="com.(your browser activity)"
android:screenOrientation="portrait">
I know that there are some posts here but they are not solving my problem.
The thing is:
I have a Cordova App (android platform). In my activity_main.xml I have declared a CordovaWebView and I want to call loadUrl() method to load a website that is in my assets folder. When I invoke the method the app crashes showing "UNFORTUNATELY, MyApp HAS STOPPED".
STRANGE THINGS I HAVE NOTICED:
If I emulate using a device with API 10 or 16, this WORKS FINE. If I test it with 17 it does NOT WORK.
If I don't use CordovaWebView and directly invoke: this.loadUrl("file:///android_asset/www/index.html"); it works fine, but it's like I am not using the layouts I define (so I don't have my ad banner).
Any ideas about this problem??
Thanks!
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="#+id/layout_home"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/layout_body"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_above="#+id/layout_banner"
android:background="#color/abc_search_url_text_normal">
<org.apache.cordova.CordovaWebView
android:id="#+id/webview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#color/common_signin_btn_dark_text_disabled" />
</LinearLayout>
<RelativeLayout
android:id="#+id/layout_banner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/wallet_hint_foreground_holo_dark">
</RelativeLayout>
</RelativeLayout>
MainAcitivy.java
public class MainActivity extends CordovaActivity {
CordovaWebView cwv;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
..LOAD ADVERTISEMENT INTO LAYOUT_BANNER...
cwv = (CordovaWebView) findViewById(R.id.webview);
cwv.getSettings().setJavaScriptEnabled(true);
cwv.loadUrl("file:///android_asset/www/index.html");
}
look the doc : https://cordova.apache.org/docs/en/3.5.0/guide_platforms_android_webview.md.html
cwv = (CordovaWebView) findViewById(R.id.cordovaview);
Config.init(this);
cwv.loadUrl(Config.getStartUrl());
you can see a sample here : https://github.com/dam1/sample-android-cordova-webview
Why do you need activity_main.xml and all android stuff, just start a fresh project using cordova command line. You don't need any xml of that sort in standard cordova project.
You've got cordova plugins for displaying admob ads inside cordova web view, see http://plugreg.com/search?q=admob
I have an application that's based on alfresco android sdk. After user login to the server MainActivity starts. The MainActivity has few fragments in itself. One fragment contains webview, some buttons and textview. Here is the code of xml layout:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/prop"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/video_layout"
android:layout_width="match_parent"
android:layout_height="192dp"
android:orientation="horizontal"
android:gravity="center" >
<WebView
android:id="#+id/video_web_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
.
.
.
</LinearLayout>
</ScrollView>
When the layout is displayed webview should load url of page with HTML5 video but only blank page is shown. After a while blank page changes to grey. I observed that it means page is load and it show the page with html5 video after user scroll layout. This happens with every url what I've try.
In the test activity I use the same layout and the page with video is loaded and displayed correctly.
In the fragment and in the test activity I use the same code for setting webview and loading the url. Javascript is enabled and I use WebChromeClient like is recommended in WebView docummentation. Also i have INTERNET permission in applications Manifest.
Here is the code from onCreate method from test activity :
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.web_video);
web = (WebView)findViewById(R.id.video_web_view);
.
.
.
web.setWebChromeClient(new WebChromeClient());
WebSettings webSettings = web.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setAllowContentAccess(true);
webSettings.setAllowFileAccess(true);
webSettings.setPluginState(PluginState.ON);
webSettings.setDomStorageEnabled(true);
web.setHorizontalScrollBarEnabled(false);
web.setVerticalScrollBarEnabled(false);
webSettings.setRenderPriority(RenderPriority.HIGH);
webSettings.setUseWideViewPort(false);
webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
web.loadUrl(someUrl);
}
The same code contains onCreateView in fragment. Only difference is that user have to be login to the server for displaying fragment.
I almost forgotten on errors from Logcat :
02-28 09:34:20.832: V/chromium(9079): external/chromium/net/host_resolver_helper/host_resolver_helper.cc:66: [0228/093420:INFO:host_resolver_helper.cc(66)] DNSPreResolver::Init got hostprovider:0x5354b220
02-28 09:34:20.832: V/chromium(9079): external/chromium/net/base/host_resolver_impl.cc:1515: [0228/093420:INFO:host_resolver_impl.cc(1515)] HostResolverImpl::SetPreresolver preresolver:0x018ee018
02-28 09:34:21.182: V/WebRequest(9079): WebRequest::WebRequest, setPriority = 1
02-28 09:34:21.382: V/chromium(9079): external/chromium/net/disk_cache/hostres_plugin_bridge.cc:52: [0228/093421:INFO:hostres_plugin_bridge.cc(52)] StatHubCreateHostResPlugin initializing...
02-28 09:34:21.392: V/chromium(9079): external/chromium/net/disk_cache/hostres_plugin_bridge.cc:57: [0228/093421:INFO:hostres_plugin_bridge.cc(57)] StatHubCreateHostResPlugin lib loaded
02-28 09:34:21.392: V/chromium(9079): external/chromium/net/disk_cache/hostres_plugin_bridge.cc:63: [0228/093421:INFO:hostres_plugin_bridge.cc(63)] StatHubCreateHostResPlugin plugin connected
02-28 09:34:21.392: V/chromium(9079): external/chromium/net/http/http_cache.cc:1167: [0228/093421:INFO:http_cache.cc(1167)] HttpCache::OnBackendCreated HostStat created
02-28 09:34:21.392: E/chromium(9079): external/chromium/net/disk_cache/stat_hub.cc:213: [0228/093421:ERROR:stat_hub.cc(213)] StatHub::Init - App org.alfresco.mobile.android.samples isn't supported.
02-28 09:34:21.392: E/chromium(9079): external/chromium/net/disk_cache/stat_hub.cc:213: [0228/093421:ERROR:stat_hub.cc(213)] StatHub::Init - App org.alfresco.mobile.android.samples isn't supported.
02-28 09:34:22.222: D/skia(9079): notifyPluginsOnFrameLoad not postponed
Does anyone know what i do wrong? Have anyone some suggestion taht could help me?
Thanks for your answer and sorry for my bad english.
So I figured out what I did wrong. It had something to do with acceleration. I simply added following line to my code:
mWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
and It solved my problem.
I had the same problem. below code segment solved the problem
WebView webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.setWebChromeClient(new WebChromeClient());
webView.loadUrl(url);
Check that you have included the INTERNET PERMISSION in AndroidManifest file .
<uses-permission android:name="android.permission.INTERNET" />
please add
android:hardwareAccelerated="true"
in your webview activity class file. because in android 3.0+ its supports only if we add this line in android manifest file.
After looking at this post and doing some other research I finally figured out what my issue was. My manifest was right, my layout and webview setup was all correct. However, the URL that I was passing into my WebViewActivity class was not formatted correctly. The difference is very subtle...
I had my URL formatted a certain way:
FORMAT: "scheme://www.websitename.com//"
EXAMPLE: "http://www.awebsite.com//"
It turns out however some websites are not formatted exactly this way and the job of a browser is to fill in the blanks for you. For instance, you can just type "google.com" into a browser and it will know to take you to "https://www.google.com/". The Android WebView does not do this.
The fix:
Visit the website that you are trying to load in a desktop browser and copy the URL after the website loads.
Paste it directly into your Java code:
final String websiteURL = "http://awebsite.com//";
Note that there is no "www." on this URL. Some websites require "www." and some do not. Again, copy the URL from your desktop web browser to determine whether or not the "www." is needed. Another thing to note is that on the end of this URL there is a double-slash "//".
Bottom line, the Android WebView is finicky and it requires that the string URL be exactly right or it will start tossing up errors like this one:
12-16 13:40:26.518: E/chromium(13869): external/chromium/net/disk_cache/stat_hub.cc:216: [1216/134026:ERROR:stat_hub.cc(216)] StatHub::Init - App com.nucitrus.thestory isn't supported.
I hope this helps!
I've been banging my head against a wall this afternoon trying to get a WebView to work. Below is the code in the main class:
public class fkyougoogle extends Activity {
/** Called when the activity is first created. */
WebView webview;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
// WORKS
//webview.loadUrl("http://www.google.com");
// DOESN'T WORK
//webview.loadUrl("http://www.theregister.co.uk");
//webview.loadData("<html><body>hello</body></html>", "text/html", "utf-8");
//webview.loadDataWithBaseURL("fake://", "<html><body>hello</body></html>", "text/html", "utf-8", "http://www.theregister.co.uk/");
}
}
This is Google's "Hello, Webview" example. If I use a WebView and try to access www.google.com then it works fine. If I try to access any other site then it fails including loadData and it just displays a black screen in the emulator. In the end I would like to read from a local file.
is included under the manifest tag and the XML schema is the same as the Hello Webview example.
Am I missing something obvious here? :(
Try changing
android:layout_width="wrap_content"
android:layout_height="wrap_content"
to
android:layout_width="fill_parent"
android:layout_height="fill_parent"
in your main.xml top level LinearLayout
It should look like this:
<?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"
android:orientation="vertical">
<WebView
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
Try UTF-8 instead of utf-8 for your latter two attempts. I have no problem loading http://www.theregister.co.uk using the same code -- try loading it in the built-in Browser app, and if that fails, you're perhaps encountering some sort of firewall/proxy issue.
Here are a few projects demonstrating simple uses of WebView, from one of my books.
I had similar problem of a WebView being completely blank, but it my case it was caused by a missing android.permission.INTERNET uses-permission.