Reputation: 65
Am Trying to add webview on my android activity but its the activity page does not shows my given url please help me.?
DMS.java
package com.agte.vivo;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class Dms extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dms);
WebView myWebView = (WebView) findViewById(R.id.webView);
//myWebView.loadData("yourCode Html to load on the webView " , "text/html" , "utf-8");
myWebView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}});
myWebView.loadUrl("192.168.7.175/app/app.html");
}
}
Activity DMS
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.agte.vivo.Dms">
<WebView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/webView"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true" />
</RelativeLayout>
there is no error shown but i need to to open the webpage same in android app how to fix this.?
Upvotes: 1
Views: 508
Reputation: 6884
From what I can see there is nothing wrong with the code. Your issue is because you are trying to access a URL which is not available, since it is not yet exposed to the internet.
Just for the sake of testing that there is nothing wrong in the url, I recommend changing 192.168.7.175/app/app.html
to a more plausable website such as http://www.google.com
for the time being.
Your next step is to find a way to expose your website to the web, so that it is accessible from your device. If you have IIS installed, you can copy your website content to the C:\inetpub\www
folder. This would expose (make it available on the web) your site to anyone knowing the url. You can also use this tutorial to help you.
Upvotes: 1
Reputation: 2050
Make sure that you use the same Wifi network as your computer
Upvotes: 0
Reputation: 2405
try this:
//if you have your html file in assets folder do like this
// aboutWebview .loadUrl("file:///android_asset/About.html");
WebView aboutWebview = (WebView) findViewById(R.id.aboutus_webview);
aboutWebview .loadUrl("http://192.168.7.175/app/app.html");
WebSettings webSettings = aboutDmrWebview.getSettings();
webSettings.setJavaScriptEnabled(true);
aboutWebview .addJavascriptInterface(new JavaScriptInterface(this), "Android");
aboutDmrWebview.setWebViewClient(new MyWebViewClient());
private class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals("www.google.com")) {
// This is my web site, so do not override; let my WebView load the page
Toast.makeText(getApplicationContext(), "www.google.com", Toast.LENGTH_SHORT).show();
return false;
}
// Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;
}
}
Upvotes: 1
Reputation: 1182
Did you add this line in your manifest file ?
<uses-permission android:name="android.permission.INTERNET" />
Upvotes: 1