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 stores the Facebook user ID. |
| 2 |
Inside a try-catch block, an Intent is created to open the Facebook app.
|
| 3 | The startActivity() method is called with the intent. |
| 4 | If the Facebook app is not installed, the catch block executes. |
| 5 | In the catch block, an intent is created to open the Facebook URL in a web browser. |
| 6 | The Intent.ACTION_VIEW action is used. |
| 7 |
The startActivity() method is called again to navigate to the URL.
|
Java
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)));
}
MainActivity.java
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)));
}
MainActivity.java
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)));
}
MainActivity.java
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();
}

Comments
Post a Comment