【问题标题】:How intercept a google maps intent in Android?如何在 Android 中拦截谷歌地图意图?
【发布时间】:2011-07-25 06:46:42
【问题描述】:

我试图截获如下的谷歌地图意图:

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

但我没有找到任何示例、链接或文档。所以,我认为不幸的是这是不可能的。

在 Manifest 文件中,我放置了几个意图过滤器。特别是我认为下一个意图过滤器必须与提到的意图匹配。

<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 与意图匹配,而不是我的 Activity,而且令人惊讶的是 myIF 为空,因此我无法获得谷歌地图活动使用的意图过滤器。

此外,我从 Android Market 安装了“Intent Intercept”,但它没有捕捉到这个意图。

所以,我需要一些帮助/想法。有人知道发生了什么吗?在我看来,谷歌限制了这种拦截,但没有指定这个限制。

任何帮助将不胜感激。 最好的祝福, 巴勃罗。

【问题讨论】:

    标签: android filter android-intent maps


    【解决方案1】:

    下面的代码示例在我的项目中运行良好。

    <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>
    

    【讨论】:

      【解决方案2】:

      所以,不幸的是,我认为这是不可能的。

      我很确定是这样的。

      特别是我认为下一个意图过滤器必须与提到的意图匹配。

      您的操作字符串错误。如果你看了documentationACTION_VIEW的字符串表示是:

      android.intent.action.VIEW
      

      这不是您在 &lt;intent-filter&gt; 中所拥有的。

      【讨论】:

        【解决方案3】:

        这个清单条目对我有用:

            <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>
        

        在您的活动中,您可以检查 onCreate:

        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
          }
        }
        

        【讨论】:

          【解决方案4】:

          我也一直在努力让它发挥作用。这里似乎有几种方法:

          1) Intents with scheme: "http" or "https" with authority "maps.google.com"。这似乎像标准意图一样正常运行。 2)使用问题中提到的“地理”方案作为OP。好像这个是不开放拦截的。

          @CommonsWare 即使使用以下过滤器在清单中使用“android.intent.action.VIEW”: ,

          似乎不可能拦截它。

          当您提到“我很确定它是。”时,您的意思是 IS 可能还是 IS NOT 可能?

          【讨论】:

            【解决方案5】:

            我使用多意图过滤器,这对我有用

                        <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>
            

            【讨论】:

              【解决方案6】:

              为此,您应该在AndroidManifest.xml 文件中相应活动的&lt;activity&gt;&lt;/activity&gt; 标记内添加以下&lt;intent-filter&gt;

              <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>
              

              【讨论】:

                猜你喜欢
                • 1970-01-01
                • 2023-03-23
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                相关资源
                最近更新 更多