0

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?

Community
  • 1
  • 1
Sohaib Rahman
  • 183
  • 2
  • 19
  • Actually this statement `For determining the "facebook" app, we write (app.activityInfo.name).contains("facebook")` is wrong! You should check the package name for Facebook to be `com.facebook.katana` and for browser (I think) `com.android.browser` – Sherif elKhatib Mar 12 '13 at 12:51
  • @SherifelKhatib I dont think so coz, it determines the facebook app if it is installed. – Sohaib Rahman Mar 12 '13 at 13:47
  • 1
    I mean you should look for the whole package name and not only the string "facebook" (maybe there is another app that has the word "facebook") – Sherif elKhatib Mar 12 '13 at 13:58

0 Answers0