troubles with webview + facebook


  1. vovs

    vovs Active Member

    Hi, guys!
    Have some problem:
    I create simple Activity with webview.
    If you visit Facebook Mobile, you will notice that you can scroll to the bottom of the page and when you do, more loads posts - via default browser. But this is not working in my webview.

    The other thing that also needs to be fixed is the "More" button on the top right corner. The menu itself works when you touch the "more" button but none of the menu items are clickable in my webview.
    Can anyone help me?

    code here:

    Code (Text):
    1.  
    2. public class FacebookProjActivity extends Activity {
    3.  
    4.     WebView webview;
    5.     public String url = "http://m.facebook.com";
    6.     public String oldUrl;
    7.    
    8.     @Override
    9.     public void onCreate(Bundle savedInstanceState) {
    10.         super.onCreate(savedInstanceState);
    11.         setContentView(R.layout.main);
    12.         webview = (WebView) findViewById(R.id.webview);
    13.         //String myUserAgent = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7";
    14.         //webview.getSettings().setUserAgentString(myUserAgent);
    15.        
    16.         webview.getSettings().setSavePassword(true);
    17.         webview.getSettings().setJavaScriptEnabled(true);
    18.         webview.getSettings().setJavaScriptCanOpenWindowsAutomatically (true);
    19.         webview.getSettings().setAppCacheEnabled(true);
    20.         webview.getSettings().setPluginsEnabled(true);
    21.         webview.getSettings().setSupportMultipleWindows (true);
    22.         webview.getSettings().supportZoom();
    23.         webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    24.         webview.getSettings().setLightTouchEnabled(true);
    25.         webview.setWebViewClient(new FacebookProWebViewClient());
    26.         webview.loadUrl("http://m.facebook.com");
    27.     }          
    28.     @Override
    29.     protected void onDestroy() {  
    30.         super.onDestroy();
    31.     }
    32.    
    33.     private class FacebookProWebViewClient extends WebViewClient {
    34.         @Override
    35.         public boolean shouldOverrideUrlLoading(WebView webview, String url) {
    36.             if (webview.getUrl().startsWith("http://m.facebook") == true){
    37.                 webview.loadUrl(url);
    38.                 return true;
    39.             }else{
    40.                 return false;
    41.             }
    42.         }
    43.         public void onFormResubmission (WebView webview, Message dontResend, Message resend){
    44.         }
    45.         public void onLoadResource (WebView webview, String url){
    46.         }
    47.     }
    48. }
    49.  
    main.xml
    Code (Text):
    1.  
    2. <?xml version="1.0" encoding="utf-8"?>
    3. <LinearLayout
    4.   xmlns:android="http://schemas.android.com/apk/res/android"
    5.   android:orientation="vertical"
    6.   android:layout_width="fill_parent"
    7.   android:layout_height="fill_parent"
    8. >
    9.   <WebView xmlns:android="http://schemas.android.com/apk/res/android"
    10.     android:id="@+id/webview"
    11.     android:layout_width="fill_parent"
    12.     android:layout_height="fill_parent"
    13.   />
    14. </LinearLayout>
    15.  

    Advertisement
    :
  2. vovs

    vovs Active Member

    same result if use this code:

    Code (Text):
    1.  
    2. import android.app.Activity;
    3. import android.os.Bundle;
    4. import android.os.Message;
    5. import android.webkit.WebView;
    6. import android.webkit.WebViewClient;
    7.  
    8. public class FacebookProjActivity extends Activity {
    9.  
    10.         WebView webview;
    11.         public String url = "http://m.facebook.com";
    12.         public String oldUrl;
    13.  
    14.         @Override
    15.     public void onCreate(Bundle savedInstanceState) {
    16.         super.onCreate(savedInstanceState);
    17.         setContentView(R.layout.main);
    18.         webview = (WebView) findViewById(R.id.webview);
    19.         webview.getSettings().setJavaScriptEnabled(true);
    20.         webview.setWebViewClient(new FacebookProWebViewClient());
    21.         webview.loadUrl("http://m.facebook.com");
    22.         }
    23.         @Override
    24.         protected void onDestroy() {
    25.                 super.onDestroy();
    26.         }
    27.  
    28.         private class FacebookProWebViewClient extends WebViewClient {
    29.             @Override
    30.             public boolean shouldOverrideUrlLoading(WebView webview, String url) {
    31.                         webview.loadUrl(url);
    32.                         return true;
    33.             }
    34.         }
    35. }
    36.  
    any suggestions?
Loading...

Share This Page