简体   繁体   中英

Is it possible to open activity in app by clicking shared message from any social program by this app

my application shares messages to other social apps using intent with action send. what I want is that when this message clicked it openes a certain activity in my app if it is installed on the other device

Something like this can be achieved with Intent filters (assuming your app is installed on device which opens the message).

Let's say you send this URL together with your message: http://myapp.com/whatever (format is up to you). After user will click on the link the following will happen:

  1. Intent to open URL will be sent by messaging app.
  2. System will look through installed apps on your device and their intent-filters.
  3. If more than 1 intent-filter accepts the request, user will be prompted to select the Activity which he would like to use to open the link.

OK, now that we know how it works under the hood let's declare our own intent-filter for our URL:

<activity android:name=".MyActivity">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.BROWSABLE" />
            <category android:name="android.intent.category.DEFAULT" />

            <data
                android:host="myapp.com"
                android:path="/whatever"
                android:scheme="http" />
        </intent-filter>
</activity>

Now after user will try to open your URL he will be prompted to use MyActivity to open the link.

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