Read more about the implementation here: https://www.josevarghese.com/share-button-to-share-app-content-to-specific-app/
Last active
May 18, 2020 12:20
-
-
Save josevarghese/4596de2e2415ee69686ef869077ba447 to your computer and use it in GitHub Desktop.
Add app specific content sharing button or action send button on Android Menu bar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Intent; | |
import android.net.Uri | |
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
getMenuInflater().inflate(R.menu.main_menu,menu); | |
return super.onCreateOptionsMenu(menu); | |
} | |
@Override | |
public boolean onOptionsItemSelected(MenuItem item) { | |
if (item.getItemId() == R.id.share_button) { | |
try { | |
Intent sharingIntent = new Intent(Intent.ACTION_SEND); | |
sharingIntent.setType("text/plain"); | |
String shareBody = "Hey, I'm using *Name of the Sticker App* for sending awesome Stickers on WhatsApp\n \nDownload it now: https://play.google.com/store/apps/details?id=com.yourappurlhere"; | |
sharingIntent.putExtra(Intent.EXTRA_TEXT, shareBody); | |
//change the app package id as your wish for sharing content to the specific one, WhatsApp's package id is com.whatsapp, and for facebook is com.facebook.katana | |
sharingIntent.setPackage("com.whatsapp"); | |
startActivity(sharingIntent); | |
} catch (android.content.ActivityNotFoundException ex) { | |
Intent sharingIntent1 = new Intent(Intent.ACTION_SEND); | |
sharingIntent1.setType("text/plain"); | |
String shareBody = "Hey, I'm using the best app for sending awesome Stickers called *Your App Name Here* \n \nDownload it now: https://play.google.com/store/apps/details?id=com.yourappurlhere"; | |
String shareSubject = "Stickers Android App"; | |
sharingIntent1.putExtra(Intent.EXTRA_TEXT, shareBody); | |
sharingIntent1.putExtra(Intent.EXTRA_SUBJECT, shareSubject); | |
startActivity(Intent.createChooser(sharingIntent1, "Share with friends")); | |
} | |
} else { | |
return super.onOptionsItemSelected(item); | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment