Facebook Official Android SDK - How do I open a page? - android

I would like to open the Facebook app and go directly to a Facebook page when the user presses a button in my app.
How do I do that using the official Facebook SDK?
So far, all the solutions I've seen is fairly hacky, checking to see if the FB app is installed using Package Manager or something. This might become an issue in the future, given the precedent of Package Visibility.
Another solution relies on a list of unofficial URIs sourced from the decompiled Facebook APK, which can break at any time.

I have tried this code. It is work to open the facebook application
https://stackoverflow.com/a/52480045/14215175
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);
}
if you want to intent to the specific profile / Group / Page , you need to change the code
fb://profile --> "fb://group" / "fb://page"

Related

How to open a specific album or photo in facebook app using intent from your own Android App

How to open an album or photo in facebook app using intent from your own Android App?
I been searching for the specific answer for this one. Most question are about how to open a facebook page via intent.
I saw this one (regards to Sunny a Sr. Software engineer at iAppStreet) but it doesn't work.
public Intent getOpenFacebookIntent(String pId) {
try {
activity.getPackageManager().getPackageInfo("com.facebook.katana", 0);
return new Intent(Intent.ACTION_VIEW, Uri.parse("facebook:/photos?album=0&photo=" + pId+"&user="+ownerId));
} catch (Exception e) {
return new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/"));
}
}
startActivity(getOpenFacebookIntent(pid));
thanks.
Actually i made this question to help those who have the same problem like me. As of today (28 March 2016) i just found out how to open an album using intent but i cannot open a photo using intent in the facebook app. I am a beginner in android programming so please bear with me.
I used a button to implement this. Here is the code:
Button buttonOpenALbum = (Button) findViewById(R.id.button);
buttonOpenALbum.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
//It is a album from a facebook page # www.facebook.com/thinkingarmy
String albumID = "575146485903630";
String userID = "575145312570414";
String url = "facebook:/photos?album="+albumID+"&user="+userID;
Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
});
If you want to get the albumID and userID of a facebook album try searching on google how or try this one if it helps, https://www.youtube.com/watch?v=sMEmlpmCHLc
Modifying the code to open a specific photo has not produce the expected result. Even though I included the photoID, you still end up in the album. Here is the code:
Button buttonOpenPhoto = (Button) findViewById(R.id.button);
buttonOpenPhoto.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
//It is a album from a facebook page # www.facebook.com/thinkingarmy
String albumID = "575146485903630";
String userID = "575145312570414";
String photoID = "803154029769540";
String url = "facebook:/photos?album="+albumID+"&photo="+photoID+"&user="+userID;
Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
});
I can't be sure why. I tried looking but some say the urls of facebook is undocumented. If I may, I think you cannot open a specific photo because upon observation, facebook open a photo in full screen, meaning it is a different Activity than the Main Activity which handles the incoming Intent. The Main Activity of the facebook app only handles the intent up to opening a specific album.
I hope I can help other "new android coders" with my first post.
NB: I just learn coding using google and stackoverflow. It's my way of giving back. Thanks.
Launch a view intent with the following URL
https://www.facebook.com/photo.php?fbid={photo_id}
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
ctx.startActivity(browserIntent);
If the app is installed, it will prompt the user to open in app, otherwise it will use the browser
Some useful information at Open Facebook Page in Facebook App (if installed) on Android
In particular, new versions of facebook app work with
Uri.parse("fb://facewebmodal/f?href=" + FACEBOOKURL
I found this the simplest approach to acheive what was needed.
Note also that to get the URL you can go to the facebook album (on facebook desktop), click the three dots next to "Edit" and "Tag" and select "Get Link". I found this more reliable than simply copying the URL from the browser.

A link to vimeo application but

I have asked what is the code that sends a link from the application that I'm making to the vimeo application; it opens vimeo application but not the video specified in the link, does anybody knows how?
vimeo.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
try{
Intent browserIntent = null;
PackageManager pmi = getPackageManager();
browserIntent = pmi.getLaunchIntentForPackage("com.vimeo.android.videoapp");
browserIntent.setAction(Intent.ACTION_VIEW);
browserIntent.setData(Uri.parse("http://player.vimeo.com/video/83178705"));
startActivity(browserIntent);
}
catch(Exception e){
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://player.vimeo.com/video/83178705"));
startActivity(browserIntent);
}
}
});
I answered your other question with this solution. But I believe it will fix this issue as well since our vimeo-deeplink library accommodates opening our specific application.
You could include it with gradle:
compile 'com.vimeo.android.deeplink:vimeo-deeplink:1.0.0'
And then deeplink to your video with this method:
boolean handled = VimeoDeeplink.showVideoWithUri(Context context, String videoUri)
Where videoUri is equal to /videos/83178705.
By doing this below, it will reset all your app preference
Go to Settings->Apps, choose from menu Reset app preferences and confirm Reset apps.
After that,
choose it in Settings->Apps and press Clear defaults button for vimeo app
Now try to open that video link(vimeo link) again. Now it'll ask you to select which app to use. Then select your vimeo app as default

Facebook Android App Link

I have a new app and I'm trying to implement it to "Call to Action" facebook page button, but I have no idea what I shall write in the "App link" text box.
They put an example link of: example://location/123456
But I have no idea what it's refering to or what's the App Link of my app.
Tried to find anything about it on the Internet but couldn't find any helpful solution since I have no app links in my app (no products etc)
My goal is that when the user clicks on Facebook "Use App", it will redirect him to the app or the google play store app page if it's not installed..
I'm not talking about open app in my app, im talking about open my app in my facebook page
You can use the next code from the wiki:
/** Open another app.
* #param context current Context, like Activity, App, or Service
* #param packageName the full package name of the app to open
* #return true if likely successful, false if unsuccessful
*/
public static boolean openApp(Context context, String packageName) {
PackageManager manager = context.getPackageManager();
try {
Intent i = manager.getLaunchIntentForPackage(packageName);
if (i == null) {
return false;
//throw new PackageManager.NameNotFoundException();
}
i.addCategory(Intent.CATEGORY_LAUNCHER);
context.startActivity(i);
return true;
} catch (PackageManager.NameNotFoundException e) {
return false;
}
}
Example usage:
openApp(this, "com.google.android.maps.mytracks");
You can read it from here
To post a message in FB, see the next post, maybe it will be useful How to open the Facebook Write Post with some pre defined text and image
You should use Try/Catch. if user have Facebook app, fb://page/12345 link will open in app. Else, Catch code will run.
#Override
public void onClick(View v) {
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri
.parse("fb://page/12345"))); //12345 is Facebook page number
} catch (Exception e) {
//open play link in browser
startActivity(new Intent(Intent.ACTION_VIEW, Uri
.parse("http://play.google.com/etc")));
}
}

Open Facebook User Profile Android

When I try to open a Facebook Profile through the official Facebook App i have this error: error loading the biography, the content is not available.
I tried with many codes but nothing. Only if Facebook App is not installed on the device work right with the browser.
Here is the current code:
try
{
Intent followIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/"+id_facebook));
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/"+id_facebook));
startActivity(followIntent);
}
}, 1000 * 2);
}
catch (Exception e)
{
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/"+id_facebook)));
String errorMessage = (e.getMessage()==null)?"Message is empty":e.getMessage();
Log.e("Unlock_ScreenActivity:FacebookAppNotFound" ,errorMessage);
}
UPDATE:
When I give up and i only put the https URI, Android let me choose between Facebook APP and the browser, and i like it! So my question is answered =D
I ran into a similar problem back in the day and found out that when I tried to use the same method as you it only worked if I wanted to view my own profile (or the current logged in user in the Facebook app) but whenever I tried to show someone else's facebook page so I eventually came across this answer:
https://stackoverflow.com/a/24547437/1879664
Long story short, it's no longer possible and the only workaround so far is to make facebook load the web page inside facebook just like you've mentioned but the difference is that without forcing it, if the user can't choose between apps or has already selected another browser as a default app you can no longer open that page through facebook. With this code you can ensure that it will always open that page with the facebook app if it's installed or it would load with your default browser. Here's the code that I use in my apps:
try {
mActivity.getPackageManager().getPackageInfo("com.facebook.katana", 0);
String url = "https://www.facebook.com/profile.php?id=USER_ID"
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://facewebmodal/f?href="+url));
}
mActivity.startActivity(intent);
} catch (Exception e) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/profile.php?id=USER_ID"));
mActivity.startActivity(intent);
e.printStackTrace();
}

Open Facebook Place's Page from Android App

I'm Trying to open my app page on facebook so users can like it
I followed this solution, but can't seem to find a way to access pages through facebook's scheme mechanism, using the solution code, with my page id open my page in facebook's android app, but like button is missing, and subscribing page fails.
found the answer:
public static Intent getOpenFacebookIntent(Context context) {
try {
//context.getPackageManager().getPackageInfo("com.facebook.katana", 0);
return new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/576525422362966"));
} catch (Exception e) {
return new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/576525422362966"));
}
}

Categories

Resources