【问题标题】:How to share a location to a Whatsapp contact?如何将位置分享给 Whatsapp 联系人?
【发布时间】:2014-11-18 03:28:54
【问题描述】:

我想将我的位置分享给 Whatsapp 联系人。

我不知道我必须使用什么 mimeType。这是我要分享的代码:

Intent waIntent = new Intent(Intent.ACTION_SEND);
waIntent.setPackage("com.whatsapp");
waIntent.setType("text/plain");
waIntent.putExtra(Intent.EXTRA_TEXT, "geo:23.1097,-82.4094");
startActivity(waIntent);

但这只会发送纯文本,而不是像 Whatsapp 那样的位置。有什么想法吗??

【问题讨论】:

  • 这是因为你使用的是 waIntent.setType("text/plain");
  • 这就是问题所在,我不知道我必须使用什么类型。

标签: android location whatsapp


【解决方案1】:

注意:我没有(也不想拥有)Whatsapp,但也许我的发现对你有帮助

由于 "geo:..." 是一个 uri(定义为 here),您应该将其包装成一个 Uri 并将其作为数据发送。

此代码适用于其他位置感知 Android 应用,如 GoogleMaps

String uriString = "geo:23.1097,-82.4094";

Intent waIntent = new Intent();
// waIntent.setPackage("com.whatsapp");
Uri uri = Uri.parse(uriString);

waIntent.setData(uri); // finds several apps on my phone including googleMaps
// waIntent.setDataAndType(uri, "*/*"); // does not work on my phone: nothing found
Toast.makeText(this, appName + "Starting " + uriString, Toast.LENGTH_SHORT).show();

try {
    this.startActivity(Intent.createChooser(waIntent,"Choose app to show location"));
} catch (Exception e) {
    Toast.makeText(this, appName + e.getMessage(), Toast.LENGTH_SHORT).show();
    e.printStackTrace();
}

你可以检查whatsapp是否也理解这一点

【讨论】:

  • 对不起,whatsapp 不明白,我已经尝试了几乎所有方法,但它无法识别“geo:...”Uri。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-07
  • 1970-01-01
  • 2014-03-22
  • 2015-12-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多