Making own Android App default for map intents

≡放荡痞女 提交于 2020-01-06 23:46:07

问题


I have been working on an android application which uses google maps it is map related application. i want my to be able to handle implicit intents like if user click on map link like Latitude and longitude my app should handle the intent and show that position on map. Like default Google Maps Application. Is it possible then what piece of code for intent specific activity?


回答1:


Add an intent-filter in the Manifest so your app can respond to map URLs:

<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="maps.google.com" />
    <data android:scheme="https" android:host="maps.google.com" />
    <data android:scheme="geo"/>
</intent-filter>

Once in your app, you can retrieve the URI using this code:

protected void onCreate(Bundle savedInstanceState) {
    Intent intent = getIntent();  
    Uri data = intent.getData(); // Here you will receive the URI

    // ...
}


来源:https://stackoverflow.com/questions/38115729/making-own-android-app-default-for-map-intents

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