share location with share intent Activity

2019-02-12 12:23发布

I need to share location from my app using the share intent activity, I have gone through some examples and know how to implement share intent. However I am stuck at setType. I need my application to share location details as well the users location on a map.

By the way i copied a users code with a very similar question"no offence"

Any assistance would be really appreciated.

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")); 

2条回答
虎瘦雄心在
2楼-- · 2019-02-12 12:55

Here is the code to fire an intent to the map with a location:

String uri = "geo:" + latitude + ","
                    +longitude + "?q=" + latitude
                    + "," + longitude;
startActivity(new Intent(android.content.Intent.ACTION_VIEW,
                    Uri.parse(uri)));
查看更多
唯我独甜
3楼-- · 2019-02-12 13:15
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"));
查看更多
登录 后发表回答