简体   繁体   中英

Open link with facebook app in android

Please see the two links below. When pasted in Whatsapp, first one opens with Facebook app, but the second one opens with browser.

Opens in Facebook app:

https://m.facebook.com/SriSwamiji/posts/1099353043449548:0

Opens in Browser:

https://www.facebook.com/SriSwamiji/photos/a.186720728046122.67368.108460819205447/1099353043449548/?type=3

What makes the second link open in browser ? I want to open it via Facebook app.

I would say that is due to deep linking . In any of your apps you could add filters that trigger your app whenever the Android system tries to resolve an URL.

Probably the Facebook app has configured the deep link of the http://m.* urls

edit: I've tested it via adb and it is due to deep linking. You can test it with

adb shell am start -W -a android.intent.action.VIEW -d <URL>

as explained in the deep link documentation

This is the output:

$ adb shell am start -W -a android.intent.action.VIEW -d "https://m.facebook.com/SriSwamiji/posts/1099353043449548:0"
Starting: Intent { act=android.intent.action.VIEW dat=https://m.facebook.com/... }
Status: ok
Activity: com.facebook.katana/com.facebook.deeplinking.activity.StoryDeepLinkLoadingActivity
ThisTime: 127
TotalTime: 208
WaitTime: 253
Complete

As you can see the Activity launched is com.facebook.katana (the Facebook app).

$ adb shell am start -W -a android.intent.action.VIEW -d "https://www.facebook.com/SriSwamiji/photos/a.186720728046122.67368.108460819205447/1099353043449548/?type=3"
Starting: Intent { act=android.intent.action.VIEW dat=https://www.facebook.com/... }
Status: ok
Activity: com.android.chrome/org.chromium.chrome.browser.document.DocumentActivity
ThisTime: 121
TotalTime: 179
WaitTime: 223
Complete

In this case com.android.chrome is launched

Also, if you take a look to the Facebook app manifest (with some app like ManifestViewer you can see that it has some intent-filter to handle it:

        <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="http"
                android:host="m.facebook.com"
                android:pathPrefix="/events"/>
            <data
                android:scheme="https"
                android:host="m.facebook.com"
                android:pathPrefix="/events"/>
            <data
                android:scheme="http"
                android:host="m.facebook.com"
                android:pathPrefix="/groups"/>
            <data
                android:scheme="https"
                android:host="m.facebook.com"
                android:pathPrefix="/groups"/>
            <data
                android:scheme="http"
                android:host="www.facebook.com"
                android:pathPrefix="/groups"/>
            <data
                android:scheme="https"
                android:host="www.facebook.com"
                android:pathPrefix="/groups"/>
            <data
                android:scheme="http"
                android:host="www.facebook.com"
                android:pathPrefix="/events"/>
            <data
                android:scheme="https"
                android:host="www.facebook.com"
                android:pathPrefix="/events"/>
        </intent-filter>

In your concrete case I would say that that link is handled in

    <activity
        android:theme="@2131625627"
        android:name="com.facebook.katana.ContactUriHandler"
        android:taskAffinity="com.facebook.task.ContactUriHandler"
        android:excludeFromRecents="true"
        android:launchMode="singleInstance">
        <intent-filter>
            <action
                android:name="android.intent.action.VIEW"/>
            <category
                android:name="android.intent.category.DEFAULT"/>
            <data
                android:mimeType="vnd.android.cursor.item/vnd.facebook.profile"
                android:host="com.android.contacts"/>
            <data
                android:mimeType="vnd.android.cursor.item/vnd.facebook.presence"
                android:host="com.android.contacts"/>
        </intent-filter>
    </activity>

and internally has support for posts but not for photos

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM