1 android facebook facebook-graph-api
我正在尝试使用特定用户 ID 在我的 android 应用程序中打开某些 Facebook 个人资料页面。如果已安装,我的代码会打开 facebook 应用程序,否则打开 webbrowser。它工作正常,除非安装了 facebook 应用程序并关闭了它。在这种情况下,它只会打开新闻源页面而不是个人资料页面。当 facebook 应用程序在后台打开时,它成功地重定向到所需的个人资料页面。我该如何解决这个问题?还有一个官方的facebook文档描述了访问facebook应用程序URI的方式吗?
try{
this.getPackageManager()
.getPackageInfo("com.facebook.katana", 0); //Checks if FB is even installed.
final String facebookScheme = String.format("fb://profile/%s", user2FbID);
final Intent facebookIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(facebookScheme));
facebookIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY
| Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
startActivity(facebookIntent);
}catch (Exception e) {
String facebookScheme = "https://m.facebook.com/" + user2FbID;
Intent facebookIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(facebookScheme));
startActivity(facebookIntent);
}
Run Code Online (Sandbox Code Playgroud)
试试这个,对我有用
try
{
Intent followIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/<your profile_id>"));
startActivity(followIntent);
final Handler handler = new Handler();
handler.postDelayed(new Runnable()
{
@Override
public void run() {
Intent followIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/<your profile_id>"));
startActivity(followIntent);
}
}, 1000 * 2);
}
catch (Exception e)
{
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/<user_name>")));
String errorMessage = (e.getMessage()==null)?"Message is empty":e.getMessage();
Log.e("Unlock_ScreenActivity:FacebookAppNotFound" ,errorMessage);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3272 次 |
| 最近记录: |