Passing Multiple Text/plain Values In Share Intent
I am creating a notepad application in android. I have given a functionality to share individual note with other apps. I want the share function to share the title and content of
Solution 1:
I found a way to pass multiple strings with just one EXTRA_TEXT
.
I wanted to pass two values, namely, title and content, So I stored the value of title in a string called "title" and the value of content in a string called "content".
Now, the trick ! I concatenated both the strings together and stored that concatenated string to a new string and passed that string into EXTRA_TEXT
.
I am gonna share my correct code just to give a clear picture.
String title=noteModel.getTitle();
String content=noteModel.getContent();
String titleAndContent="Title: "+title+"\n Content: "+content;
Intent intentShare = newIntent();
intentShare.setAction(Intent.ACTION_SEND);
intentShare.setType("text/plain");
intentShare.putExtra(Intent.EXTRA_TEXT,titleAndContent);
context.startActivity(intentShare);
Solution 2:
You used the same key for two Extra
intentShare.putExtra(Intent.EXTRA_TEXT,title);
intentShare.putExtra(Intent.EXTRA_TEXT,content);
You have to use a different key for every extra you pass. Change the content extra similar to below one.
intentShare.putExtra(Intent.EXTRA_CONTENT,content);
Solution 3:
intentShare.putExtra(Intent.EXTRA_TEXT,title);
intentShare.putExtra(Intent.EXTRA_TEXT,content); ///ovewriting value
please use different key
Solution 4:
try this
intentShare.putExtra(android.content.Intent.EXTRA_SUBJECT, title);
intentShare.putExtra(android.content.Intent.EXTRA_TEXT, content);
Post a Comment for "Passing Multiple Text/plain Values In Share Intent"