Open Facebook Profile, Page and Group from Android app?
Welcome to our latest tutorial on how to open Facebook profiles, pages, and groups directly from your Android app! In this video, we'll walk you through step-by-step instructions on how to seamlessly navigate and interact with your favorite Facebook content using your mobile device.
how the code works:
Serial Number | Description |
---|---|
1 |
fb_Uid The variable `fb_Uid` stores the Facebook user ID. |
2 |
try-catch block
Inside a try-catch block, the code creates an Intent to open the Facebook app using the Intent.ACTION_VIEW action and a URI with the Facebook profile URL. |
3 |
startActivity()
The `startActivity()` method is called with the created intent to open the Facebook app. |
4 |
If an exception occurs (e.g., the Facebook app is not installed), the catch block is executed. |
5 |
Inside the catch block, another Intent is created to open the Facebook profile URL in a web browser. |
6 |
Intent.ACTION_VIEW
The `Intent.ACTION_VIEW` action and the Facebook profile URL are used to create the intent. |
7 |
startActivity()
The startActivity() method is called again with the new intent to open the browser and navigate to the Facebook profile. |
How to open facebook profile?
String fb_Uid = "100012186064725";
try {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/"+fb_Uid));
startActivity(intent);
} catch (Exception e){
startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("https://www.facebook.com/"+fb_Uid)));
}
How to open facebook page?
String fb_Uid = "100063624096325";
try {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/"+fb_Uid));
startActivity(intent);
} catch (Exception e){
startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("https://www.facebook.com/"+fb_Uid)));
}
How to open facebook group?
String fb_Uid = "1872452446373863";
try {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://group/"+fb_Uid));
startActivity(intent);
} catch (Exception e){
startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("https://www.facebook.com/"+fb_Uid)));
}
how to send message in facebook
String fb_Uid = "100012186064725";
try {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb-messenger://user/"+fb_Uid));
intent.putExtra(Intent.EXTRA_TEXT, "My message to send");
startActivity(intent);
} catch (Exception e){
Toast.makeText(this, "Please Install Messenger", Toast.LENGTH_SHORT).show();
}
String fb_Uid = "100012186064725";
try {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb-messenger://user/"+fb_Uid));
intent.putExtra(Intent.EXTRA_TEXT, "My message to send");
startActivity(intent);
} catch (Exception e){
Toast.makeText(this, "Please Install Messenger", Toast.LENGTH_SHORT).show();
}
Tutorial Video :
Thank You 💗