public static Intent getOpenFacebookIntent(Context context,String url) { try { context.getPackageManager().getPackageInfo("com.facebook.katana", 0); return new Intent(Intent.ACTION_VIEW, Uri.parse(url)); } catch (Exception e) { return new Intent(Intent.ACTION_VIEW, Uri.parse(url)); } }
I used this code and it was working but now it does not. I need any intent to open a url in Facebook directly. This post helped me, Open Facebook page from Android app?
Advertisement
Answer
Open facebook url
private void openFacebookApp() { String facebookUrl = "www.facebook.com/XXXXXXXXXX"; String facebookID = "XXXXXXXXX"; try { int versionCode = getActivity().getApplicationContext().getPackageManager().getPackageInfo("com.facebook.katana", 0).versionCode; if(!facebookID.isEmpty()) { // open the Facebook app using facebookID (fb://profile/facebookID or fb://page/facebookID) Uri uri = Uri.parse("fb://page/" + facebookID); startActivity(new Intent(Intent.ACTION_VIEW, uri)); } else if (versionCode >= 3002850 && !facebookUrl.isEmpty()) { // open Facebook app using facebook url Uri uri = Uri.parse("fb://facewebmodal/f?href=" + facebookUrl); startActivity(new Intent(Intent.ACTION_VIEW, uri)); } else { // Facebook is not installed. Open the browser Uri uri = Uri.parse(facebookUrl); startActivity(new Intent(Intent.ACTION_VIEW, uri)); } } catch (PackageManager.NameNotFoundException e) { // Facebook is not installed. Open the browser Uri uri = Uri.parse(facebookUrl); startActivity(new Intent(Intent.ACTION_VIEW, uri)); } }
Add query in manifest
<queries> <package android:name="com.google.android.gm" /> <package android:name="com.facebook.katana" /> <intent> <action android:name="android.intent.action.VIEW" /> <data android:scheme="https" /> </intent> <intent> <action android:name="android.intent.action.DIAL" /> <data android:scheme="tel" /> </intent> <intent> <action android:name="android.intent.action.SEND" /> <data android:mimeType="*/*" /> </intent> </queries>