androiddeep-linkingapplinksandroid-deep-linkandroid-app-links

How to manage andorid deeplink and Applink in one Activity?


How to manage the deeplink and applink in one Activity? This is current AndroidManifest.xml setting.

    <activity android:name=".MainActivity" 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="peterworks" android:host="open"/>
        </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="https" android:host="peterworks.io"/>
        </intent-filter>
    </activity>

Solution

  • This is sample code that manage your deeplinkActivity with deeplink and Android Applink.

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    
        // onNewIntent Method will process every deeplink data.
        onNewIntent(MainActivity.this.getIntent());
    
    }
    
    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
    
        // setIntent should be called for get new deeplink data. If this is not called, always same deeplink will called
        setIntent(intent);
    
        // Deeplink data process start
        Uri myDeeplink = intent.getData();
    
        if (myDeeplink != null){
    
            if(myDeeplink.getScheme().equals("https")) {
             // Do your things when Android Applink is open your app.
    
            } else {
             // Do your things when Deeplink is open your app.
    
            }
    
        }
    
    }