Intent Filter for handling address press in Contact?

风流意气都作罢 提交于 2019-12-14 02:22:14

问题


Folks, when viewing a contact, you can press on the address to view that address in a map application (such as Google Maps or VZW Navigator). I would like define an intent-filter such that my app will show up in the list of apps that can handle said intent. Any ideas?

Thanks in advance.

From logcat, I see the following from ActivityManager:

Starting activity: 
Intent { act=android.intent.action.VIEW dat=content://com.android.contacts/data/6792 cmp=android/com.android.internal.app.ResolverActivity }

I've tried a several combinations of intent-filters, e.g.:

<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=”geo” />
</intent-filter>

<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=”content” android:host=”com.android.contacts” android:pathPattern=”/data/*” />
</intent-filter>

回答1:


in ICS you should use this:

        <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="geo" />
        </intent-filter>

The received intent should be handled accordingly (diffrently). please note that on ICS and with this intent-filter you don't need a special permission to read contact address.




回答2:


The solution, provided by Google Developer Relations is:

<intent-filter android:label="MyApp">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="vnd.android.cursor.item/postal-address_v2" />
</intent-filter>



回答3:


for early versions of Android I used

        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="vnd.android.cursor.item/*" android:host="com.android.contacts" android:pathPrefix="/data" android:scheme="content"/>
        </intent-filter>



回答4:


VIEW is supposed to be capitalized. Yours is not.



来源:https://stackoverflow.com/questions/4890797/intent-filter-for-handling-address-press-in-contact

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!