android - 如何创建从我的应用到 Facebook 页面的意图?
问题描述
这似乎是一个已成定局的问题,我认为我已经可以很容易地找到答案,但我找到的答案已经很老了,而且它们不起作用。如何创建从我的应用到 Facebook 页面的意图?我希望如果有打开 Facebook 应用程序,否则浏览器
到目前为止,最好的解决方案是 Rishav Singla:
public static Intent getOpenFacebookIntent(Context context) {
try {
context.getPackageManager().getPackageInfo("com.facebook.katana", 0);
return new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/<id_here>"));
} catch (Exception e) {
return new Intent(Intent.ACTION_VIEW,
Uri.parse("https://www.facebook.com/<user_name_here>"));
}
}
利用:
startActivity(getOpenFacebookIntent(getApplicationContext()));
... 在 attesa di altre soluzioni
解决方案
您可以使用以下代码重定向到特定用户您的 facebook 应用程序将在后台,因此为了打开它,您必须运行此代码两次(这是一个奇怪的行为 :( )
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);
}
希望这可以帮助您快乐编码!
推荐阅读
- react-native - Visual Studio 代码错误:-无法启动流程错误:流程版本错误。配置指定版本 ^0.92.0 但这是版本 0.95.1
- openssl - 如何在 openSSL 1.1.1 中禁用 TLS1.3
- c# - 有没有办法将 SelectMany 用于字典
- python - 在 Ubuntu 18.04 中使用 MySQLdb 或连接器将 Python 与 MySQL 连接
- aws-lambda - Alexa 在超时时发送 SessionEndedRequest 然后向用户显示错误卡
- laravel-5 - laravel + vue 路由器无法从 url 获取参数
- data-structures - 为什么在红黑树上使用堆?
- php - jenssegers/laravel-mongodb 的 where() 和 raw() 对同一查询产生不同的结果
- java - 将插件移动到父 pom
- java - 休眠 - 线程“主”java.lang.IndexOutOfBoundsException 中的异常:索引:0,大小:0