我想将我的位置共享给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那样的位置。有什么想法吗?
发布于 2015-01-16 22:09:31
注意:我没有(也不想要) Whatsapp,但我的发现可能会对你有所帮助
因为"geo:...“是一个uri (定义的here),您应该将其封装到Uri中并作为数据发送。
此代码适用于其他位置感知的安卓应用程序,如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是否也理解这一点
https://stackoverflow.com/questions/26986092
复制相似问题