How to access and pass parameters to the modules of an Android Instant App

前端 未结 3 2165
-上瘾入骨i
-上瘾入骨i 2020-12-17 15:02

With normal installed apps it\'s possible to use the technique of Deep Linking in order to not only open a specific application from an URL but also to redirect it to

3条回答
  •  醉话见心
    2020-12-17 15:28

    Instant Apps and Deep Linking

    Instant Apps rely on App Links to work, and App Links are just one type of deep link. So deep linking is still possible for Instant Apps, and is in fact absolutely critical to how they function. However, URI scheme deep linking (which is still very prevalent in Android apps) is not supported.

    The difference between a regular app and an Instant App is that the device will only load a single Activity in response to the App Link the user clicks, instead of needing to download the full package through the Play Store. It's a more seamless experience for the user, but the underlying technology works the same way.

    Passing Custom Parameters

    If the user clicks an App Links-enabled URL like http://www.myinstantappexample.com/onlyviewmap/?x=0.000&y=0.000, you will get that entire string back inside the app after it opens. You'll have to parse out the x and y variables yourself, but they will be available to you. Something like this:

    Uri data = this.getIntent().getData();
    if (data != null && data.isHierarchical()) {
        String uri = this.getIntent().getDataString();
        Log.i("MyApp", "Deep link clicked " + uri);
    }
    

    You'll just need to manipulate the uri value to find what you need.

    Alternative Approach to Custom Parameters

    Alternatively, you can use Branch.io (full disclosure: I'm on the Branch team) to power your links. We have full support for Instant Apps, and this allows you to work with a much more friendly data format. We let you create links like this, to control every part of the behavior:

    branch.link({
        tags: [ 'tag1', 'tag2' ],
        channel: 'facebook',
        feature: 'dashboard',
        stage: 'new user',
        data: {
            x: '0.000',
            y: '0.000',
            '$desktop_url': 'http://myappwebsite.com',
            '$ios_url': 'http://myappwebsite.com/ios',
            '$ipad_url': 'http://myappwebsite.com/ipad',
            '$android_url': 'http://myappwebsite.com/android',
            '$og_app_id': '12345',
            '$og_title': 'My App',
            '$og_description': 'My app\'s description.',
            '$og_image_url': 'http://myappwebsite.com/image.png'
        }
    }, function(err, link) {
        console.log(err, link);
    });
    

    In return you get a URL like http://myappname.app.link/iDdkwZR5hx, and then inside the app after the link is clicked, you'll get something that looks like this:

    {
        tags: [ 'tag1', 'tag2' ],
        channel: 'facebook',
        feature: 'dashboard',
        stage: 'new user',
        data: {
            x: '0.000',
            y: '0.000'
        }
    }
    

提交回复
热议问题