【问题标题】:How do you get a location from the GoogleMaps app and use it in your own app?您如何从 GoogleMaps 应用程序中获取位置并在您自己的应用程序中使用它?
【发布时间】:2015-11-26 10:21:38
【问题描述】:

我正在尝试从 GoogleMaps 应用中检索目标位置并在我自己的应用中使用它,但到目前为止我找不到任何有关如何执行此操作的文档。

如需更详细的说明:如果您启动 google maps 应用程序并长按地图上的任何位置,则会在该位置上设置一个标记。如果您点击该标记,则会显示该位置的详细信息。除其他外,这些详细信息中有一个“共享”按钮。当您点击该按钮时,将显示能够接受共享位置的应用程序列表。我希望我的应用出现在那里!

我想:由于此信息将作为意图发送,因此我需要将我的应用注册为适当意图的意图过滤器。但是我需要听什么意图?

在清单中它看起来像这样:

<activity android:name="My Activity">
    <intent-filter android:label="My App">
        <!-- What goes here? -->
    </intent-filter>
</activity>

收到此信息后,我希望我的应用会出现在上述列表中。下一步是处理接收到的数据。那么,我从意图中获得的数据是什么样的? 是否有任何默认 API 来处理这些数据?

感谢任何帮助。我知道我无法提供“到目前为止我尝试过什么”这样的很多细节,但我真的找不到对我有帮助的 API 描述。

【问题讨论】:

    标签: android google-maps android-intent


    【解决方案1】:

    看看http://developer.android.com/training/sharing/receive.html。

    您需要:

    1. 在清单中更新 Activity 的 Intent 过滤器

      <intent-filter>
          <action android:name="android.intent.action.SEND" />
          <category android:name="android.intent.category.DEFAULT" />
          <data android:mimeType="text/plain" />
      </intent-filter>
      
    2. 将代码添加到您的活动以处理意图

      Intent intent = getIntent();
      String action = intent.getAction();
      String type = intent.getType();
      
      if (Intent.ACTION_SEND.equals(action) && type != null && "text/plain".equals(type)) {
          String text = intent.getStringExtra(Intent.EXTRA_TEXT);
          // Do whatever you want with the text
      }
      

    【讨论】:

      猜你喜欢
      • 2017-01-26
      • 2012-03-20
      • 1970-01-01
      • 2013-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多