I have added a share
option in my app & I want to share some plain text with it.
The problem is that suppose I chose to share with WhatsApp. After clicking the share option, when I choose a contact to share with, nothing gets shared & I get returned back to my app.
Here is what I've done so far:
LinearLayout linearLayoutShareAppContainer = (LinearLayout) findViewById(R.id.share_app_container);
linearLayoutShareAppContainer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final Handler handler3 = new Handler();
handler3.postDelayed(new Runnable() {
@Override
public void run() {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(Intent.EXTRA_TEXT, R.string.share_content);
startActivity(Intent.createChooser(sharingIntent, "Share via..."));
}
}, 200);
}
});
As I'm a beginner, I'm unable to figure out the problem here.
Please let me know.
Thanks.
You're sending a resource id instead of text. Try replacing R.string.share_content
with getString(R.string.share_content)
.
Also, you shouldn't need to do this with a Runnable
in a Handler
. You can create your Intent
and call startActivity()
directly in onClick()
.