2016-09-15 11 views
0

どのようにユーザー名からFacebookプロフィールを開くことができますか?またはFacebookプロフィールを取得するためにAndroidで使用する必要があるリクエストAndroid:ユーザー名からアプリのFacebookプロフィールを開く

Intent intent; 

try { 
    activity.getPackageManager() 
      .getPackageInfo("com.facebook.katana", 0); // Checks if FB is even installed. 
    intent = new Intent(Intent.ACTION_VIEW, 
      Uri.parse("fb://profile/" + famous)); // Trys to make intent with FB's URI 
} catch (Exception e) { 
    intent = new Intent(Intent.ACTION_VIEW, 
      Uri.parse("https://www.facebook.com/" + famous)); // catches and opens a url to the desired page 
} 

activity.startActivity(intent); 

はこれを試みたが、ユーザー名では動作しませんでした( - ログインしているユーザー - ユーザーのに行くの壁)とid(挿入された静的には、エラーが表示さ - このプロファイルを読み込むことができませんでした)...

答えて

1

あなたはfb://profile/fb://page/もはや作品として、開くには、次を使用することができますが、fb://facewebmodal/f?href=[YOUR_FACEBOOK_PAGE]

public static Intent newFacebookIntent(PackageManager pm, String url) { 
    Uri uri = Uri.parse(url); 
    try { 
    ApplicationInfo applicationInfo = pm.getApplicationInfo("com.facebook.katana", 0); 
    if (applicationInfo.enabled) { 
     uri = Uri.parse("fb://facewebmodal/f?href=" + url); 
    } 
    } catch (PackageManager.NameNotFoundException ignored) { 
    } 
    return new Intent(Intent.ACTION_VIEW, uri); 
} 

urlを使用することができます。完全なURLをFacebookページやプロフィールに。

pmContext#getPackageManager()

関連する問題