It seemed a foregone question and I thought I could easily find an answer already, but the answers I found are very old and they do not work. How do I create a intent from my app to facebook page? I would like that if there is open the Facebook app, otherwise the browser
Up to now the best SOLUTION is that of 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>"));
}
}
use:
startActivity(getOpenFacebookIntent(getApplicationContext()));
... in attesa di altre soluzioni
You can use below code to redirect to specific user Your facebook app would be in background, so in order to open it you have to run this code twice(That's a weird behaviour :( )
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);
}
Hope this helps you Happy coding!