2012-10-01 117 views
6

我需要使用共享意向活动从我的应用程序共享位置,我已经通过一些示例并了解如何实施共享意向。但是我被困在setType中。我需要我的应用程序共享位置详细信息以及用户在地图上的位置。与共享意向共享位置活动

顺便说我复制一个用户码有非常类似的问题“没有犯罪”

任何援助将非常感激。

Intent intent1 = new Intent(Intent.ACTION_SEND); 
intent1.setType("text/plain"); 
intent1.putExtra(Intent.EXTRA_TEXT, "The status update text"); 
startActivity(Intent.createChooser(intent1, "Select prefered Service")); 

回答

8

下面是火的意图与位置地图代码:

String uri = "geo:" + latitude + "," 
        +longitude + "?q=" + latitude 
        + "," + longitude; 
startActivity(new Intent(android.content.Intent.ACTION_VIEW, 
        Uri.parse(uri))); 
+0

感谢了很多,但它不是我想要的,你的代码打开了谷歌地图。我不想开始谷歌地图我只需要我的应用程序能够分享我的当前位置更像谷歌地图共享位置 –

+0

只需添加一个笔记为任何人采取这个例子,并与它一起运行。如果您自定义“q”参数,请确保您安全地构建Uri:'String uri = Uri.Builder()。scheme(“geo”)。appendPath(lat +“,”+ lng).appendQueryParameter(“q” ,name).build();' –

3
Double latitude = user_loc.getLatitude(); 
Double longitude = user_loc.getLongitude(); 

String uri = "http://maps.google.com/maps?saddr=" +latitude+","+longitude; 

Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); 
sharingIntent.setType("text/plain"); 
String ShareSub = "Here is my location"; 
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, ShareSub); 
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, uri); 
startActivity(Intent.createChooser(sharingIntent, "Share via"));