2012-10-01 5 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

おかげで多くが、そのない、あなたのコードはGoogleマップを開きます。私はGoogleマップを開始したいとは思わない私はちょうどGoogleマップの共有場所のように私の現在の場所を共有することができるようにするために私のアプリが必要です –

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