2017-07-07 46 views
0

我需要在我已安裝的Facebook應用程序中打開Facebook頁面。我已要求下面的函數,該函數:通過Facebook應用程序而不是瀏覽器打開Facebook頁面的問題

private void loadFacebookUrl() { 
    if (Constant.isOnline(AboutActivity.this)) { 
     try { 
      if (appInstalledOrNot(AboutActivity.this, "com.facebook.katana")) { 
       this.getPackageManager().getPackageInfo("com.facebook.katana", 0); 
       startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/MyPage/")).setPackage("com.facebook.katana")); 
      } else { 
       startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=com.facebook.katana"))); 
      } 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } else { 
     Constant.displayToast(AboutActivity.this, getResources().getString(R.string.msg_internet)); 
    } 
} 

但是,我得到我的logcat以下異常:

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=https://www.facebook.com/... pkg=com.facebook.katana } 
07-07 14:19:24.070 5094-5094/com.app.thelist W/System.err:  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1805) 
07-07 14:19:24.070 5094-5094/com.app.thelist W/System.err:  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1514) 
07-07 14:19:24.070 5094-5094/com.app.thelist W/System.err:  at android.app.Activity.startActivityForResult(Activity.java:3978) 
07-07 14:19:24.070 5094-5094/com.app.thelist W/System.err:  at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:50) 
07-07 14:19:24.070 5094-5094/com.app.thelist W/System.err:  at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:79) 
07-07 14:19:24.070 5094-5094/com.app.thelist W/System.err:  at android.app.Activity.startActivityForResult(Activity.java:3939) 
07-07 14:19:24.070 5094-5094/com.app.thelist W/System.err:  at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:859) 
07-07 14:19:24.071 5094-5094/com.app.thelist W/System.err:  at android.app.Activity.startActivity(Activity.java:4262) 
07-07 14:19:24.071 5094-5094/com.app.thelist W/System.err:  at android.app.Activity.startActivity(Activity.java:4230) 
07-07 14:19:24.071 5094-5094/com.app.thelist W/System.err:  at com.app.thelist.activity.AboutActivity.loadFacebookUrl(AboutActivity.java:98) 
07-07 14:19:24.071 5094-5094/com.app.thelist W/System.err:  at com.app.thelist.activity.AboutActivity.onClick(AboutActivity.java:76) 

我應該怎麼做才能獲得任務做了什麼?謝謝。

回答

0

你的問題是在鏈接的格式...你應該使用:FB:// facewebmodal/F HREF =

Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://facewebmodal/f?href=https://www.facebook.com/mypage")); 

檢查他是否有應用程序,然後使用上面的URL格式,否則將他重定向到瀏覽器:

String pageurl = "https://www.facebook.com/mypage"; 
boolean hasFacebook = appInstalledOrNot(AboutActivity.this, "com.facebook.katana"); 
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse((hasFacebook?("fb://facewebmodal/f?href="):"") + pageurl)); 
startActivity(i); 
相關問題