I m beginner in android. i want to open twitter url in webview. i have a twitter url(http://twitter.com/..). i try to this code but can not open in webview.
code:
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress)
{
activity.setTitle(" Loading...");
activity.setProgress(progress * 100);
if(progress == 100){
activity.setTitle(R.string.app_name);
//view.canGoBack();
}
}
});
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url){
view.loadUrl(url);
view.canGoBack();
return true;
}
});
//The URL that webview is loading
webView.loadUrl(uri);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(event.getAction() == KeyEvent.ACTION_DOWN){
switch(keyCode)
{
case KeyEvent.KEYCODE_BACK:
if(webView.canGoBack() == true){
webView.goBack();
}else{
finish();
}
开发者_开发百科 return true;
}
}
return super.onKeyDown(keyCode, event);
}
help me.....
I got solution in my Question
webView.getSettings().setUserAgentString("Mozilla/5.0 (Linux; U; Android 2.0; en-us; Droid Build/ESD20) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17");
try this:
Uri uri = Uri.parse(Place your URL here);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
Hope this Helps:
DisplayWeb.java:
public class DisplayWeb extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.web);
String url = "http://www.twitter.com";
System.out.println("++++URL GOT = "+url);
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.getSettings().setBuiltInZoomControls(true);
myWebView.getSettings().setSupportZoom(true);
myWebView.loadUrl(url);
Button back = (Button) findViewById(R.id.back);
back.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
DisplayDirections.this.finish();
}
});
}
}
web.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</RelativeLayout>
Hope this help!
I had the same issue and have been doing some searching to look for possible answers to this problem.
Hacking the Browser Agent might work but it's not really a good idea.
The solution given in this post also worked for me and I think is a better solution: Problems loading mobile.twitter in webview
Hope that helps.
精彩评论