簡體   English   中英

如何在Android中截取谷歌地圖意圖?

[英]How intercept a google maps intent in Android?

我試圖截取谷歌地圖意圖如下:

Intent myIntent = new Intent(android.content.Intent.ACTION_VIEW,Uri.parse(“geo:37.423156,-122.084917”));

但我沒有找到任何關於此的示例,鏈接或文檔。 所以,我想不幸的是,這是不可能的。

在Manifest文件中,我放了幾個intent過濾器。 特別是我認為下一個意圖過濾器必須與提到的意圖相匹配。

<intent-filter>
<action android:name="android.content.Intent.ACTION_VIEW" />
        <data android:scheme="geo"/>
    </intent-filter>

此外,我嘗試通過以下方式調查哪些活動與此特定意圖相匹配:

List resolves = getPackageManager().queryIntentActivities(myIntent, 0 );
ResolveInfo firstRevolve=(ResolveInfo) resolves.get(0);
IntentFilter myIF=firstRevolve.filter;

然而,只有MapsActivity與intent相匹配,而不是我的Activity,並且令人驚訝的是myIF為null,因此我無法獲得google maps活動使用的intent過濾器。

另外我從Android Market安裝了“Intent Intercept”,但它沒有捕獲這個意圖。

所以,我需要一些幫助/想法。 有人知道發生了什么事嗎? 在我看來,谷歌限制了這種攔截,但未指定此限制。

任何幫助將不勝感激。 最好的問候,巴勃羅。

下面的代碼示例在我的項目中正常工作。

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

這個清單條目對我有用:

    <activity
        <intent-filter>  
          <!-- Filter to run activity without geo --> 
            <action android:name="com.example.MYACTION" />                
            <category android:name="android.intent.category.DEFAULT" />                     
        </intent-filter>
        <intent-filter>   
            <!-- Filter for geo scheme geo -->                  
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />               
            <data android:scheme="geo" />
        </intent-filter>
    </activity>

在您的活動中,您可以查看創建:

protected void onCreate(Bundle savedInstanceState) {
  Intent intent = getIntent();  
  String action = intent.getAction();
  Uri data      = intent.getData();

  if(      Intent.ACTION_VIEW.equals(action) ) {
    if(data != null && "geo".equals(data.getScheme())) {  

      // do something with geo uri data
    }
  }
  else {
    // Code for activity when it`s started without geo uri
  }
}

所以,我想不幸的是,這是不可能的。

我很確定它是。

特別是我認為下一個意圖過濾器必須與提到的意圖相匹配。

你有錯誤的動作字符串。 如果您閱讀文檔ACTION_VIEW的字符串表示ACTION_VIEW為:

android.intent.action.VIEW

這不是你的<intent-filter>

我一直試圖讓這個也工作。 這里似乎有幾種方式:

1)具有方案的意圖:具有權限“maps.google.com”的“http”或“https”。 這看起來像標准意圖一樣正常。 2)使用“geo”方案作為問題中提到的OP。 似乎這是不容易被截獲的。

@CommonsWare即使在清單中使用“android.intent.action.VIEW”並使用以下過濾器:

它似乎無法攔截它。

當你提到“我寧願相信它是。”,你的意思是這可能的,或者是不可能的?

我使用多意圖過濾器,這與我合作

            <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="google.navigation"/>
            </intent-filter>

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

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

為此,您應在AndroidManifest.xml文件中的相應ACTIVITY的<activity></activity>標記內添加以下<intent-filter>

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM