App link not working for facebook on android

2019-03-04 13:49发布

问题:

Facebook app link is not working. link contains the following:

<html>
    <head>
    <meta property="al:android:url" content="myapp://12345" />
    <meta property="al:android:package" content="com.my.app" />
    <meta property="al:android:app_name" content="myApp" />
    <meta property="al:web:should_fallback" content="false" />
    </head>
</html>

Androidmanifest is like the following:

<activity
 android:name="com.my.app.MyAppActivity" 
 android:launchMode="singleTask"
   <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
   </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="myapp" />
</intent-filter>

Meta property in the html should be responsible for launching intent from the Facebook app but opening the link through facebook doesn't launch the application. Where I am getting wrong?

回答1:

This how App Link working for me to share with friends via Facebook or other sharing intent.

Share Intent Code

Intent intent=new Intent(android.content.Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, "Lets Enjoy");
intent.putExtra(Intent.EXTRA_TEXT, "Lets Enjoy" + "http://myApp.com/id/"+12345);
startActivity(Intent.createChooser(intent, "Share With Friends")); 

Android Manifest.

 <activity
        android:name="com.package.youractivitytoopen"
        android:theme="@style/MyMaterialTheme"
        android:screenOrientation="portrait">
        <intent-filter>
            <category android:name="android.intent.category.DEFAULT" />
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data
                android:scheme="http"
                android:host="myApp.com"
                android:pathPrefix="/id/" ></data>
        </intent-filter>
 </activity>

If you sharing data then you will get data like that

Intent intentShare = getIntent();
String action = intentShare.getAction();
Uri data = intentShare.getData();
if(data!=null) {
   String url = data.toString();
   String[] separated = url.split("/");
   id= Integer.parseInt(separated[4]);
}

Share with your friends via share intent if they have application it will show option to open with app and opened at the activity you set in manifest.

https://developer.android.com/training/app-indexing/deep-linking.html