How to implement share via option in android?
Asked Answered
K

3

17

I want to implement something like this. share via

It should not be hard coded. If user haven't installed Dropbox there should not be a option to share via Dropbox.

Thanks in advance !

Koroseal answered 29/12, 2011 at 7:25 Comment(0)
B
49

You can do the same by using:

Intent i=new Intent(android.content.Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(android.content.Intent.EXTRA_SUBJECT,"Subject test");
i.putExtra(android.content.Intent.EXTRA_TEXT, "extra text that you want to put");
startActivity(Intent.createChooser(i,"Share via"));

Detailed example is here for your reference: http://mobile.tutsplus.com/tutorials/android/android-sdk-implement-a-share-intent/

Belated answered 29/12, 2011 at 7:39 Comment(1)
Hi @Paresh Mayani ,hey nice solution can I add more custom option in that createChooser Dialog box ??Smelser
A
2

For Sharing the Content Via:

Intent shareIntent =  new Intent(android.content.Intent.ACTION_SEND); 

//set type  

shareIntent.setType("text/plain");  

//add what a subject you want

shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"add what a subject you want");  

 String shareMessage="message body"; 

//message  

shareIntent.putExtra(android.content.Intent.EXTRA_TEXT,shareMessage); 

//start sharing via 

startActivity(Intent.createChooser(shareIntent,"Sharing via"));  
Aegis answered 25/3, 2016 at 11:36 Comment(0)
B
0

in KOTLIN :

startActivity(createShareIntent(url))


fun createShareIntent(url: String): Intent = Intent.createChooser(Intent().apply {
    action = Intent.ACTION_SEND
    putExtra(Intent.EXTRA_TEXT, url)
    type = "text/plain"
}, null)

Hope it will helpful.

Bequest answered 1/9, 2022 at 11:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.