Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲

從自家 App 直接開啟高德地圖的功能頁:URI 與 featureName 參數整理

編輯:關於 Android 程式設計

專案裡需要從第三方應用直接跳到高德地圖的「電子狗」頁面,翻遍開發者論壇也沒找到說明,最後只能靠反編譯 APK 把對外 URI 挖出來。這篇文章把結果記錄下來,省下其他人重複做一次的功夫。

前提很直接:使用者手機上必須已安裝高德地圖,否則找不到對應的 Activity,會拋出 ActivityNotFoundException。

入口 URI 的結構

從 AndroidManifest.xml 可以看到一組以 androidamap 為 scheme 的 intent-filter,其中和「開啟功能頁」相關的是 host 為 openFeature 的那一組:

<intent-filter>
    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.BROWSABLE"/>
    <data android:host="openFeature" android:scheme="androidamap"/>
</intent-filter>

也就是說,完整的呼叫格式為:

androidamap://openFeature?featureName=你要的功能

其他可用的 host 還包括 navi(導航)、poi(地點詳情)、viewMap、myLocation、route、bus、showTraffic、indoorMap、multiPointShow(多點顯示)、rootmap(回到主地圖)等。

featureName 有哪些值

參數解析集中在 MainIntentDispatcher 這個類別中,它會讀取 query 參數 featureName 再分派到各個 Fragment。可用的值大致如下:

featureName對應頁面備註
DirectNavigation直接導航—
CitySelect切換城市—
SpecialTopic專題/活動頁—
Subway地鐵圖可帶 adcode 指定城市
EasyDriving順暢出行—
Illegal違章查詢需登入
Favorite收藏夾—
Layers / OpenTraffic路況圖層—
ExternalURL內嵌外部網頁需帶 url 參數(需 URL 編碼)
Cleaning快取清理提示—
ShortCut新增導航捷徑—
GoldCoin高德金幣page=history 可開紀錄頁
TrafficRadio交通廣播需連網
openTrafficRemind路況提醒需連網
openTrafficTopBoard路況看板需連網
openTrafficEdog電子狗需連網
PoiDetail地點詳情需 x、y、poiname、poiid
VoiceSearch語音搜尋—
Account帳戶未登入會先跳登入
User個人中心—
Wallet錢包—
Mine「我的」內頁搭配 page、item 使用

Mine 的 page 與 item 組合對應到更多子頁面,例如 page=ToolBox 搭配 item 為 ElectronicEye(電子狗)、Traffic(路況提醒)、Violation(違章)、Subway(地鐵)、Maincollect(路檢收藏)、AutonaviGold(金幣)、TravelHelper(出行助手);page=Fortune 則對應另一組頁面。

實際呼叫範例

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);

ComponentName cn = new ComponentName(
        "com.autonavi.minimap",
        "com.autonavi.map.activity.NewMapActivity");

intent.setAction("com.autonavi.minimap.ACTION");
intent.setData(Uri.parse("androidamap://openFeature?featureName=openTrafficEdog"));
intent.setComponent(cn);

try {
    startActivity(intent);
} catch (ActivityNotFoundException e) {
    // 使用者未安裝高德地圖,引導至應用商店
    Toast.makeText(this, "請先安裝高德地圖", Toast.LENGTH_SHORT).show();
}

換成其他頁面時,只要替換 featureName 的值即可。若不想指定 ComponentName,也可以簡化為直接 startActivity(new Intent(Intent.ACTION_VIEW, uri)),由系統自行挑選能處理該 scheme 的應用。

使用前請注意

這些參數是從特定版本(7.5.8 系列)的 APK 中推得,屬於非官方約定,高德隨時可能更名、增刪或加上簽章驗證,正式專案請不要把它當成穩定 API 依賴。若需求是長期維護的產品功能,建議改用高德官方提供的 URI API 或 URL Scheme 文件,並準備好「未安裝」與「版本過舊」兩種降級路徑。此外,多數功能頁需要網路連線,離線時高德會自行彈出提示而無法進入頁面。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © Android教程網 All Rights Reserved