1

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.....

Durgesh Patel
  • 326
  • 2
  • 7
  • 20

4 Answers4

1

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");
Durgesh Patel
  • 326
  • 2
  • 7
  • 20
0

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.

Community
  • 1
  • 1
Keab42
  • 688
  • 13
  • 28
0

try this:

Uri uri = Uri.parse(Place your URL here);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
Vineet Shukla
  • 23,865
  • 10
  • 55
  • 63
0

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!

Shah
  • 4,990
  • 10
  • 48
  • 70
  • noo try it its a web view to add aweb view inside yout own layout. You can edit the Layout as you want.. this is just an example how to add the webview inside your activity and layout. – Shah Aug 01 '11 at 12:51
  • Just add the WebView element where you want in the layout and then add the implementation where you have used the corressponding layout. – Shah Aug 01 '11 at 12:52
  • I am trying load weburl in webview but every time I goto browser, there is any way to stay in current activity and load weburl in webview. If I load data like webView.loaddata(), then it's open in current activity, I don't know why that happen – Hitesh Dhamshaniya Jan 23 '12 at 06:37