简体   繁体   中英

How to open a specific activity from an external link clicking

I know this question is not new, but its a bit different from already asked questions. I have a website that provides links to my app. The links direct users to specific data on my app. This is the layout of my app: I have 4 activities as Activity1.class, Activity2.class, Activity3.class, and of course the MainActivity.class which is the launcher activity.

My worry is this: On my website, I have 3 buttons: button 1 goes to open directly Activity1 on my app (assuming the app is already installed on the device), Button 2 on website opens Activity2 in my app.

Note: the app and the website are not by any means linked.

My question is: how to get a URL link to specific activity on my app. I need 3 URLs that open different 3 activities. I need these links for external use, such that they open a specified activity whey clicked.

Something like: http://myapppackage/ACTIVITY1 .

This is just an example.

In you AndroidManifest.xml add intent-filters to the activities like this

   <activity android:name=".ACTIVITY1">
        <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="http"
                android:host="myapppackage"
                android:pathPattern="/ACTIVITY1" />
        </intent-filter>
    </activity>

    <activity android:name=".ACTIVITY2">
        <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="http"
                android:host="myapppackage"
                android:pathPattern="/ACTIVITY2" />
        </intent-filter>
    </activity>   

     <activity android:name=".ACTIVITY3">
        <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="http"
                android:host="myapppackage"
                android:pathPattern="/ACTIVITY3" />
        </intent-filter>
    </activity>  

For more info check this out

Deep Linking In Android

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM