問題描述
當我使用這段代碼時
string url = "somegooglemapsurl.com";
Intent mapLauncherIntent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(url));
startActivity(mapLauncherIntent);
會彈出一個選擇對話框,詢問我是否要在地圖應用程序或瀏覽器中打開此地圖.我希望從我的應用程序活動到 Google 地圖的過渡是無縫的.如何抑制此對話框并告訴 android 在地圖活動中打開地圖?
A selection dialog pops up asking if I want to open this map in the maps application or the browser. I'd like the transition from my application activity to Google Maps to be seamless. How can I suppress this dialog and tell android to open the map in the maps activity?
當我進入谷歌地圖時,我想在某個位置使用公共蒸騰打開一個方向提示.我可以通過 google maps url 做到這一點,但是 url 會彈出選擇對話框.
When I get into Google Maps I want to open a directions prompt using public transpiration in a certain location. I can do this through a google maps url, but a url brings up the selection dialog.
推薦答案
我還沒有找到完美的解決方案,但這至少可以打開預先選擇正確目的地和公共交通的地圖.然后用戶所要做的就是點擊方向按鈕.
I haven't found a perfect solution, but this will at least open maps with the correct destination and public transportation pre-selected. Then all the user has to do is hit the directions button.
它還會檢查是否安裝了谷歌地圖,如果安裝了,則更喜歡使用它.
It also checks if google maps is installed and prefers to use that if so.
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?daddr=0,0%20(Imaginary%20Place)&dirflg=r"));
if (isAppInstalled("com.google.android.apps.maps")) {
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
}
startActivity(intent);
// helper function to check if Maps is installed
private boolean isAppInstalled(String uri) {
PackageManager pm = getApplicationContext().getPackageManager();
boolean app_installed = false;
try {
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
app_installed = true;
} catch (PackageManager.NameNotFoundException e) {
app_installed = false;
}
return app_installed;
}
這篇關于禁止谷歌地圖意圖選擇對話框的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!