2015年1月6日 星期二

Android-筆記 Open Facebook App

之前讓使用者拜訪 Facebook 的時候,
都是開啟網頁,覺得不是很理想,
後來想到之前有和其它開發者聊到,
寫在這邊備忘。


基本上就是先檢查有沒有安裝Facebook,沒有的話就用一般瀏覽器開啟。
private Intent openFacebook() {
     
 Context context = this;
  
 try {
     context.getPackageManager().getPackageInfo("com.facebook.katana", 0); 
      //Checks if FB is even installed.
     return new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/254175194653125")); 
     //Trys to make intent with FB's URI
 } catch (Exception e) {
     return new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/sentiapps")); 
     //catches and opens a url to the desired page
 }
}
上面的範例是打開個人專頁,如果要開粉絲團,要改一下Type。
facebook:/chat
facebook:/events
facebook:/friends
facebook:/inbox
facebook:/info
facebook:/newsfeed
facebook:/places
facebook:/requests
facebook:/wall

fb://root
fb://feed
fb://feed/{userID}
fb://profile
fb://profile/{userID}
fb://page/{id}
fb://group/{id}
fb://place/fw?pid={id}
fb://profile/{#user_id}/wall
fb://profile/{#user_id}/info
fb://profile/{#user_id}/photos
fb://profile/{#user_id}/mutualfriends
fb://profile/{#user_id}/friends
fb://profile/{#user_id}/fans
fb://search
fb://friends
fb://pages
fb://messaging
fb://messaging/{#user_id}
fb://online
fb://requests
fb://events
fb://places
fb://birthdays
fb://notes
fb://places
fb://groups
fb://notifications
fb://albums
fb://album/{%s}?owner={#%s}
fb://video/?href={href}
fb://post/{postid}?owner={uid}¹
參考文件
http://stackoverflow.com/questions/10788247/opening-facebook-app-on-specified-profile-page
http://stackoverflow.com/questions/4191492/launch-facebook-app-from-other-app

沒有留言:

張貼留言