Launch custom android application from android bro

2018-12-31 00:54发布

Can anybody please guide me regarding how to launch my android application from the android browser?

15条回答
不再属于我。
2楼-- · 2018-12-31 01:26

Hey I got the solution. I did not set the category as "Default". Also I was using the Main activity for the intent Data. Now i am using a different activity for the intent data. Thanks for the help. :)

查看更多
流年柔荑漫光年
3楼-- · 2018-12-31 01:27

For example, You have next things:

A link to open your app: http://example.com

The package name of your app: com.example.mypackage

Then you need to do next:

1) Add an intent filter to your Activity (Can be any activity you want. For more info check the documentation).

        <activity
        android:name=".MainActivity">

        <intent-filter android:label="@string/filter_title_view_app_from_web">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <!-- Accepts URIs that begin with "http://example.com" -->

            <data
                android:host="example.com"
                android:scheme="http" />
        </intent-filter>

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

    </activity> 

2) Create a HTML file to test the link or use this methods.

<a href="intent://example.com#Intent;scheme=http;package=com.example.mypackage;end">Open your Activity directly (just open your Activity, without a choosing dialog). </a>

<a href="http://example.com">Open this link with browser or your programm (by choosing dialog).</a>

3) Use Mobile Chrome to test

4) That's it.

And its not necessary to publish app in market to test deep linking =)

Also, for more information, check documentation and useful presentation.

查看更多
闭嘴吧你
4楼-- · 2018-12-31 01:27

Felix's approach to handling deep links is the typical approach to handling deep links. I would also suggest checking out this library to handle the routing and parsing of your deep links:

https://github.com/airbnb/DeepLinkDispatch

You can use annotations to register your Activity for a particular deep link URI, and it will extract out the parameters for you without having to do the usual rigmarole of getting the path segments, matching it, etc. You could simply annotate and activity like this:

@DeepLink("somePath/{someParameter1}/{someParameter2}")
public class MainActivity extends Activity {
   ...
}
查看更多
倾城一夜雪
5楼-- · 2018-12-31 01:28

The following link gives information on launching the app (if installed) directly from browser. Otherwise it directly opens up the app in play store so that user can seamlessly download.

https://developer.chrome.com/multidevice/android/intents

查看更多
十年一品温如言
6楼-- · 2018-12-31 01:32

Please see my comment here: Make a link in the Android browser start up my app?

We strongly discourage people from using their own schemes, unless they are defining a new world-wide internet scheme.

查看更多
怪性笑人.
7楼-- · 2018-12-31 01:34

There should also be <category android:name="android.intent.category.BROWSABLE"/> added to the intent filter to make the activity recognized properly from the link.

查看更多
登录 后发表回答