How to show chooser Intent with my own android app

2019-08-23 10:09发布

问题:

If there's a WhatsApp chat which has location shared, when clicked it shows a chooser intent with some set of applications. I want to write an intent filter so that my application will also be listed there.

回答1:

You can do it by supporting implicit intent to your Activity. Define intent-filter to Activity to which you want to open after clicking to your Application from options.

<activity android:name=".BrowserActivitiy"
          android:label="@string/app_name">

      <intent-filter>
         <action android:name="android.intent.action.VIEW" />
         <category android:name="android.intent.category.DEFAULT" />
         <data android:scheme="http"/>
         <data android:scheme="geo"/>
      </intent-filter>
</activity>

To know more about Intents and Intent filters go to official website. https://developer.android.com/guide/components/intents-filters



回答2:

Add this to your Manifest file (Particular activity):

<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="geo" />
</intent-filter>