Not able to view webpage using webview - java

this is the xml file for the webview
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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.testing.WebViewExample">
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/webView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
and this code is for Webview.java
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView mywebview = (WebView) findViewById(R.id.webView);
mywebview.loadUrl("https://www.google.com/");
}
}
But the problem is I am not able to view the google and it show an error as webpage not available
the webpage at https://www.google.com/ could not be loaded because:
net::ERR_CACHE_MISS

You may need to add the INTERNET permission to your manifest file:
<uses-permission android:name="android.permission.INTERNET"/>
Another Reference: loadUrl() in Android Webview fails with net::ERR_CACHE_MISS

Related

Android webview not connecting to local raspberry pi server

I'm trying to create an app that uses Webview to connect to a raspberry pi web server I've created. It contains basically a few buttons that act as a garage door opener. For some reason, when I launch the app, it just displays a blank screen; but if I put in another website like Google in myWebView.loadUrl() , it loads just fine. I've added the
'<uses-permission android:name="android.permission.INTERNET" />'
inside the manifest
Here's the Activity:
public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.loadUrl("http://192.168.1.24:8000/garage.html");
}
}
Here is the xml in content_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.michael.garageopener.MainActivity"
tools:showIn="#layout/activity_main">
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
Am i doing anything wrong here?

Change background color of SearchView

I am trying to change the background color of my SearchView using both xml and code but none seems to be working.
XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<SearchView
android:id="#+id/searchView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff">
</SearchView>
</LinearLayout>
Code:
#InjectView(R.id.searchView) private SearchView searchView;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
searchView.setBackgroundColor(Color.WHITE);
}
Why are these not working and how can I solve the problem?
Add -
searchView.setBackgroundColor(Color.WHITE);
Did you connect the XML file to the activity?
For instance -
setContentView(R.layout.**YOURXMLHERE**);

Kill chrome process

I created a new project in Android. We use the following code:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.web);
webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://t.co/YoHe3NKrJH");
He is opening Chrome.
I need to close it automatically after 10s.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent" />

Open Url in webView in android

How to open this link in webView. This is running on browser but it does not run in webView android. Please give solution.
Activity:
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class WebViewActivity extends Activity {
private WebView webView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://www.google.com");
}
}
And your 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"
/>
Check this out,
it has worked for me...but i dont know whether it got any side effects or not but works fine with me
super.onCreate(savedInstanceState);
WebView theWebPage = new WebView(this);
theWebPage.getSettings().setJavaScriptEnabled(true);
theWebPage.getSettings().setPluginState(PluginState.ON);
setContentView(theWebPage);
theWebPage.loadUrl("http://www.hkmytravel.com");
Source can be found in [http://www.androidpanna.com/functionality/webview-open-url-webpage-within-the-android-app-when-launch-android-development]
Test the following:
<?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"
/>
works for me
webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("https://www.google.com/");
XML
<WebView
android:id="#+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
add in manifest
<uses-permission android:name="android.permission.INTERNET"/>

Android flash magazine application

Is it possible to create a magazine based on Android embedding flash in it?
As your question is very wilde and generic, I can only say "yes that's possible"!
Here is a link to embed your swf file into an Android application.
Load an SWF into a WebView
public class Test3Activity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String url ="file:///android_asset/qualibus.swf";
WebView wv=(WebView) findViewById(R.id.webView1);
wv.getSettings().setPluginsEnabled(true);
wv.loadUrl(url);
}
}
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<WebView android:id="#+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent">
</WebView>
</LinearLayout>
Result:

Categories

Resources