webview - ANDROID URL DIRECT APP SAYS "web page not available", ON EMULATOR IT SAYS "net::ERR_CACHE_MISS" -
i'm new android... use eclipse juno ide.
my aim direct app web page on opening it. use webview
concept. have given permissions correctly(upto knowledge). java code seems error free on eclipse.
but, on emulator says "net::err_cache_miss". when installed app on mobile, app says "web page not available"
i tried changing url www.google.co.in
, test code, despite giving preferred url. tells same. kindly me sort problems out... it'd helpful... in advance...
below given complete code androidmanifest.xml myactivity.java:
manifest.xml:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.webview" android:versioncode="1" android:versionname="1.0" > <uses-sdk android:minsdkversion="7" android:targetsdkversion="21" /> <uses-permission android:name="anroid.permission.internet"/> <uses-permission android:name="android.permissions.network_access" /> <uses-permission android:name="android.permissions.access_network_state" /> <uses-permission android:name="android.permission.write_external_storage" /> <application android:allowbackup="true" android:icon="@drawable/web_logo" android:label="@string/app_name" android:theme="@style/apptheme" > <activity android:name=".mainactivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> </application> </manifest>
activity_main.xml:
<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="fill_parent" android:layout_height="fill_parent" /> </linearlayout>
mainactivity.java:
package com.example.webview; import android.app.activity; import android.app.alertdialog; import android.content.dialoginterface; import android.os.bundle; import android.view.keyevent; import android.view.view; import android.webkit.webview; import android.webkit.webviewclient; import android.webkit.webchromeclient; import android.widget.button; import android.widget.edittext; public class mainactivity extends activity { /** called when activity first created. */ webview browser; private class webclient extends webviewclient { @override public boolean shouldoverrideurlloading(webview view, string url) { // todo auto-generated method stub view.loadurl(url); return true; } } @override protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); browser=(webview) findviewbyid(r.id.webview1); browser.setwebviewclient(new webclient()); browser.loadurl("www.google.co.in"); } @override public boolean onkeydown(int keycode, keyevent event) { if(event.getaction() == keyevent.action_down){ switch(keycode) { case keyevent.keycode_back: if(browser.cangoback()){ browser.goback(); } else { backbuttonhandler(); } return true; } } return super.onkeydown(keycode, event); } public void backbuttonhandler() { alertdialog.builder alertdialog = new alertdialog.builder( mainactivity.this); // setting dialog title // setting dialog message alertdialog.settitle(""); alertdialog.seticon(r.drawable.dialog_icon); alertdialog.setmessage("exit now?"); // setting icon dialog // setting positive "yes" button alertdialog.setpositivebutton("exit", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int which) { finish(); } }); // setting negative "no" button alertdialog.setnegativebutton("no", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int which) { // write code here invoke no event dialog.cancel(); } }); // showing alert message alertdialog.show(); } }
try full adress :
browser.loadurl("http://www.google.co.in");
all know "www" not work.
Comments
Post a Comment