Issue
I'm creating an Android application (Android 2.3.3) that has a header, a footer and a WebView between both. The problem is that the WebView is not opening any webpage. (NOTE: I'm running the app on an emulator).
I tried opening webpages using the Android browser and the webpages are opened correctly. I also tried:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
And the code works correctly (opens the page in the browser).
I've been working with www.google.com and with a domain of my own, I've also been working with the ip adress of both web pages (for google 72.14.204.147 and for my own, the ip of my own dev server).
Also, before the most popular answer is written, I already have <uses-permission android:name="android.permission.INTERNET" />
before the application tag.
I'm adding the code before anyone asks for it:
The activity java file:
public class MyActivity extends Activity {
//Global Variables
WebView mainWebView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
loadActivityViews();
mainWebView.getSettings().setJavaScriptEnabled(true);
mainWebView.loadUrl("www.google.com");
mainWebView.setWebViewClient(new MyWebViewClient());
}
/** Loads all global views of the Activity */
private void loadActivityViews(){
mainWebView = (WebView) findViewById(R.id.index_main_web_view);
}
//Internal Classes
/*
* MyWebView Class
*
* Forces links to open in the same webView
* Handles the back button.
* */
public class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event) {
if ((event.getKeyCode() == KeyEvent.KEYCODE_BACK) && view.canGoBack()) {
view.goBack();
return true;
}
return super.shouldOverrideKeyEvent(view, event);
}
}
}
The android Manifest: (NOTE: it has "android.permission.INTERNET" before the application tag)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pixable.android"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".MyActivity"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
the main.xml (I don;t think its important, but I'm adding it just in case)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/index_main_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF" >
<RelativeLayout
android:id="@+id/index_header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#000000" >
... My header butons ...
</RelativeLayout>
<WebView
android:id="@+id/index_main_web_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/index_header"
android:layout_above="@+id/index_botom_layout" />
<LinearLayout
android:id="@+id/index_botom_layout"
android:layout_width="fill_parent"
android:layout_height="50px"
android:layout_alignParentBottom="true"
android:background="#000000"
android:orientation="horizontal" >
... My Footer Butons ...
</LinearLayout>
</RelativeLayout>
</LinearLayout>
Solution
I think your issue is you're not prepending the URL with http://
. I bet you http://www.google.com
works.
Answered By - Jason Robinson
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.