ZOFTINO.COM android and web dev tutorials

Facebook Deep Linking in Android

With facebook deep linking, clicking a shared link in facebook post takes the user directly to the content view in your app. Facebook deep linking helps increase traffic and app installations as it improves the user experience.

But how to create shareable links which point to content in your app and how can you make facebook fire right intent targeting your app when user clicks the link in a facebook post?

That is exactly what I am going to show in this article. I’ll also explain difference between android deep linking and face book deep linking.

In my previous post, I explained how to make an app as a default app for certain links by following android app links and defining and publishing digital asset links file on your website.

What is Deep Linking

Deep linking in the context of mobile app allows users to directly visit the specific content in mobile apps that URI points to. For example, mobile apps can provide a feature which allows user to share a link to a specific content on social networking sites like facebook. When users click the shared link in facebook, it not only opens the app but users are taken to the specific location in the app. That behavior is possible with deep linking.

How to Implement Facebook Deep Linking

The links which you share as facebook app links on facebook are your website URL’s only. But to make them facebook app links, you need to add metadata to your web pages inside head element of each page.

 <meta property="al:android:url" content="zoftino://examples/recycleview">
    <meta property="al:android:package" content="com.zoftino">
    <meta property="al:android:app_name" content="zoftino">

When facebook app finds any link to your web page, it reads metadata from the web page then it creates URI using metadata and fires intent.

To make your app handle this intent, you need to add intent-filters to the related activity in your app.

  <intent-filter>
        <action android:name="android.intent.action.VIEW"></action>
        <category android:name="android.intent.category.DEFAULT"></category>
        <data android:scheme="zoftino"></data>
    </intent-filter>

In your activity which handles app links intent, you can read data from the intent to identify which URL is clicked and show content based on that.

So, facebook deep linking task consists of web site and mobile app changes.

But how can you create facebook app links if your app doesn’t have corresponding website. For mobile only apps, facebook provides app links hosting api using which you can create public urls and create app links.

Facebook App Links Intent Data

As mentioned above, activity in your app can know which link was clicked using intent data and extras and show specific content based on the data in intent.

If your app has a website and you added metadata to web pages, intent data field will contain value like below and intent contains al_applink_data as extras with all information about app links.

data: "zoftino://examples/recycleview?target_url=http%3A%2F%2Fzoftino.com/..."

If your app doesn’t have website and you use facebook hosting api, intent’s data field contains value like below.

data: "zoftino://examples/recycleview?target_url= https%3A%2F%2Ffb.me…”

If your app is not using facebook hosting api and is mobile only, then intent contains target_url field like below.

target_url: http://zoftino.com...

Android Deep Linking Vs Facebook Deep Linking

Android provides its own mechanism to support deep links. App links support was introduced in Android M.

Even if your app supports android app links, facebook app opens links in internal browser, providing option to open with your app like below.

So in order for your app to be opened when user clicks your app link in facebook, you need to implement facebook deep linking.

Since android supported app links are part of android system, implementing android apps links make your app as default app for links in apps other than facebook and app which support other deep linking mechanism.

Process Outbound Links in Your App Like Facebook App

If you want to process outbound links in your app like facebook app, you can do so. You can use blots sdk to fetch meta data and construct intent for out bound links. Since android system provides a way to link apps, using that would be right option in my opinion.