Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio Share button

I wanted to make a share button on a Navigation drawer, when the user touches the button it will open up that black drawer with the list of all applications and the user can share the apps Google play link. Is there any generic code template? the only answers I have found is to just share it on one application such as Facebook which seems useless because not everyone uses Facebook.

like image 699
Ryan Avatar asked Feb 10 '15 18:02

Ryan


2 Answers

Use share intent http://developer.android.com/training/sharing/send.html

sample code

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);
like image 92
yusufiga Avatar answered Oct 24 '22 05:10

yusufiga


You can send content by invoking an implicit intent with ACTION_SEND.

To send images or binary data:

final Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/jpg");
final File photoFile = new File(getFilesDir(), "foo.jpg");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(photoFile));
startActivity(Intent.createChooser(shareIntent, "Share image using"));

send an image along with text. This can be done with:

String text = "Look at my awesome picture";
Uri pictureUri = Uri.parse("file://my_picture");
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, text);
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
shareIntent.setType("image/*");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "Share images..."));

Sharing multiple images can be done with:

Intent shareIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUris);
shareIntent.setType("image/*");
like image 4
Hamid Avatar answered Oct 24 '22 06:10

Hamid