Making own Android App default for map intents

2019-09-09 13:33发布

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条回答
Bombasti
2楼-- · 2019-09-09 14:02

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

    // ...
}
查看更多
登录 后发表回答