我有 map 程序。当用户单击包含“mymaps.com”的 url 链接时 - 我的程序显示在选择器对话框中,而不是 Web 浏览器。 当用户单击链接到谷歌地图/web 或生成的应用程序/时,我想做同样的事情。 我发现了不同的 url 格式:
- > http://m.google.com/u/m/zIOcsV
- > http://maps.google.com/maps?q=45.089036,+-106.347656&num=1&t=h&vpsrc=0&ie=UTF8&z=4&iwloc=A
我想还有其他格式。 有人知道如何拦截所有格式吗?
最佳答案
使用 Intent 过滤器!有关更多信息,请参见此处:http://developer.android.com/guide/topics/intents/intents-filters.html
在您的 android list 中,在您要打开的 Activity 的标签中添加以下内容:
<intent-filter>
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" android:host="maps.google.maps" android:pathPrefix="/maps" />
</intent-filter>
然后在你的 Activity 中 像这样创建一个名为:handleIntent 的方法
private void handleIntent(Intent newIntent) {
Uri myuri = newIntent.getData();
(then use myuri to get your parameters such as q, num, etc)
(then show your map or whatever else you like with that data)
}
在您的 onCreate 中,您需要像这样调用 handleIntent
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
(init stuff would go here)
handleIntent(getIntent());
}
(可选)您可能需要像这样覆盖 onNewIntent(以防万一您的 AndroidManifest Activity configchanges 属性被调整)
@Override
protected void onNewIntent(Intent newIntent) {
setIntent(newIntent);
handleIntent(newIntent);
}
关于android - 当用户点击指向谷歌地图的链接时,如何提供我的程序作为选择?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10347471/