Android: Share plain text using intent (to all messaging apps)
Use the code as:
/*Create an ACTION_SEND Intent*/
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
/*This will be the actual content you wish you share.*/
String shareBody = "Here is the share content body";
/*The type of the content is text, obviously.*/
intent.setType("text/plain");
/*Applying information Subject and Body.*/
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, getString(R.string.share_subject));
intent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
/*Fire!*/
startActivity(Intent.createChooser(intent, getString(R.string.share_using)));
Passing Multiple text/plain values in share intent
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 = new Intent();
intentShare.setAction(Intent.ACTION_SEND);
intentShare.setType("text/plain");
intentShare.putExtra(Intent.EXTRA_TEXT,titleAndContent);
context.startActivity(intentShare);
generate image and share with intent without permission
After some researches using the suggestion of CommonsWare I managed to make it work with the following code:
TextPaint tPaint = new TextPaint();
tPaint.setTextSize(30);
tPaint.setColor(Color.BLACK);
tPaint.setStyle(Paint.Style.FILL);
StaticLayout layoutBody = new StaticLayout(textToShare, tPaint, 600, Layout.Alignment.ALIGN_CENTER, 1, 1, false);
Bitmap image = Bitmap.createBitmap(layoutBody.getWidth(), layoutBody.getHeight(), Bitmap.Config.ARGB_8888);
Canvas cs = new Canvas(image);
layoutBody.draw(cs);
cs.drawBitmap(dest, 0, 0, null);
Followed by what I found here posting it here in case it helps anyone
Related Topics
Android - How to Make Slide Menu Like Facebook, Spotify and Google +
Setonitemclicklistener on Custom Listview
Best Practice for Nested Fragments in Android 4.0, 4.1 (<4.2) Without Using the Support Library
Programmatically Collapse or Expand Collapsingtoolbarlayout
Best Practice for Defining Button Events in Android
How to Call Wi-Fi Settings Screen from My Application Using Android
Put and Get String Array from Shared Preferences
Android: Cursoradapter, Listview and Checkbox
How to Automatically Add Thousand Separators as Number Is Input in Edittext
Android Java.Lang.Noclassdeffounderror
Reading SQLite File from Asset Folder
Add a Background Image to Shape in Xml Android
How to Make a View with Rounded Corners
Sha1 Key for Debug & Release Android Studio MAC , How to Generate Sha1 Release Keys in MAC
Android How to Apply Mask on Imageview
Compile with Proguard Gives Simexception: "Local Variable Type Mismatch"