Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android facebook intent to show profile with class com.facebook.katana.ProfileTabHostActivity doesn't work any more [duplicate]

Possible Duplicate:
launch facebook app from other app

Till few days ago, in order to show to my users another user profile I used the following solution:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName("com.facebook.katana", "com.facebook.katana.ProfileTabHostActivity");
Long uid = new Long("123456789");
intent.putExtra("extra_user_id", uid);
startActivity(intent);

This solution is used by a lot of the stackoverflow users (From seeing all the questions and answers about this subject).

The last facebook app update (1.9.11), maybe even before made this solution obsolete. Now you will get the following exception for doing so:

java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.VIEW cmp=com.facebook.katana/.ProfileTabHostActivity (has extras) } from ProcessRecord... requires null

Does anyone know how can I now open the facebook app?

Thanks

like image 375
nheimann1 Avatar asked Oct 28 '12 09:10

nheimann1


1 Answers

The solution described in the question won't work anymore (In the edit of this question you can see the details why). The new version of the facebook app doesn't support anymore those kind of intents. See here the bug report

The new solution is to use the iPhone scheme mechanism (Yes, facebook decided to support the iPhone mechanism in Android instead of the implicit intent mechanism of Android).

So in order to open the facebook app with a user profile all you need to do is:

String facebookScheme = "fb://profile/" + facebookId;
Intent facebookIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(facebookScheme)); 
startActivity(facebookIntent);

If you are looking for other actions you can use the following page for all available actions (you have to test it though, since I didn't find an official publication of facebook about this)

EDIT

This part of the question is giving more details about the nature of the problem and solution, but the details above are enough in order to solve the problem.

With the new version of the facebook app, the manifest file was changed. Today the activity

com.facebook.katana.ProfileTabHostActivity

described in the manifest in the following way:

<activity android:theme="@style/Theme.Facebook"
android:name="com.facebook.katana.ProfileTabHostActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout"
android:windowSoftInputMode="adjustPan" />

Since there is no intent-filter anymore for this activity the default value of android:exported is now false. In the previous versions, there was intent-filter and then the default value was true (You are welcome to read about it here) I would like to thank this answer for the details about the exported value.

But the new version have the following activity:

<activity android:name="com.facebook.katana.IntentUriHandler">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:scheme="facebook" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="fb" />
        </intent-filter>
    </activity>

And here you can see that they support the fb and facebook scheme.

like image 155
nheimann1 Avatar answered Sep 28 '22 15:09

nheimann1