I want to know if I can open a share page in the browser instead of the Facebook app. If the Facebook app is present then share something by opening the Facebook app. Otherwise if it is not installed share the thing by opening the browser. I am using the following Stack Overflow question for guidance: Share Text on Facebook from Android App via ACTION_SEND.
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT,
"http://www.some-link-to-open.com");
PackageManager pm = getPackageManager();
List<ResolveInfo> activityList = pm.queryIntentActivities(sharingIntent, 0);
for (final ResolveInfo app : activityList) {
if ((app.activityInfo.name).contains("facebook")) {
/**
* Open Facebook app
*/
final ActivityInfo activity = app.activityInfo;
final ComponentName name = new ComponentName(
activity.applicationInfo.packageName, activity.name);
sharingIntent.addCategory(Intent.CATEGORY_LAUNCHER);
sharingIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
sharingIntent.setComponent(name);
startActivity(sharingIntent);
break;
} else if ((app.activityInfo.name).contains("internet")) {
/**
* Open Facebook in the browser.
*/
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("https://m.facebook.com/sharer.php?u="
+ "http://www.some-link-to-open.com"));
startActivity(i);
}
For determining the Facebook app, we use:
(app.activityInfo.name).contains("facebook")
So in the above code I want to know in the
else if ((app.activityInfo.name).contains("internet"))
what appropriate code you need to enter to determine the browser?