[英]How to open the Facebook App with an Android app?
我正在嘗試使用 android 應用程序打開 Facebook 應用程序或 Facebook 頁面,但我不能這樣做。 它什么也不做。
這是代碼:
public Intent getOpenFacebookIntent(Context context){
try{
context.getPackageManager().getPackageInfo("com.facebook.FacebookSdk", 0);
return new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/ID"));
} catch (Exception e) {
return new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/my_page"));
}
}
@Override
public void onClick (View v){
switch (v.getId()) {
case R.id.guardar:
startActivity(new Intent(this, getOpenFacebookIntent(this)));
break;
有人能幫助我嗎?
包名應該是這個。
details?id=com.facebook.katana
換這個。
context.getPackageManager().getPackageInfo("com.facebook.FacebookSdk", 0);
對此。
context.getPackageManager().getPackageInfo("com.facebook.katana", 0);
編輯1:
Intent facebookIntent = new Intent(Intent.ACTION_VIEW);
String facebookUrl = getOpenFacebookIntent(this);
facebookIntent.setData(Uri.parse(facebookUrl));
startActivity(facebookIntent);
調用: launchFacebook();
在您的 onClick() 方法中
public void launchFacebook() {
String urlFb = "fb://page/"+ID;
// replace ID with your id
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(urlFb));
PackageManager packageManager = getPackageManager();
List<ResolveInfo> list = packageManager.queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY);
if (list.size() == 0) {
final String urlBrowser = "https://www.facebook.com/"+my_page;
// relpace my_page with facebook profile page ending
intent.setData(Uri.parse(urlBrowser));
}
startActivity(intent);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.