Issue on sending MMS in Android version 4.0.3 - android

Hi I want to send an MMS through my application.For that my code is
void sendMMS()
{
try
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Drawable drawable = imageView.getDrawable();
Bitmap bitmapPicked = ((BitmapDrawable) drawable).getBitmap();
bitmapPicked.compress(CompressFormat.JPEG, 75, bos);
byte[] image = bos.toByteArray();
File file = new File(Environment.getExternalStorageDirectory() + File.separator + "test.jpg");
file.createNewFile();
// write the bytes in file
FileOutputStream fo = new FileOutputStream(file);
fo.write(image);
Log.i(TAG, "image = " + image);
Intent intentEmail = new Intent(Intent.ACTION_SEND);
intentEmail.setType("text/plain");
String[] recipients = new String[] { "" };
intentEmail.putExtra(Intent.EXTRA_EMAIL, recipients);
intentEmail.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
intentEmail.putExtra(Intent.EXTRA_TEXT, "body of email");
intentEmail.putExtra("sms_body", "body of sms");
intentEmail.setType("image/jpeg");
intentEmail.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + file.getAbsolutePath()));
startActivity(intentEmail);
} catch (android.content.ActivityNotFoundException ex)
{
Toast.makeText(this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
ex.printStackTrace();
} catch (Exception e)
{
e.printStackTrace();
}
}
When users click on a button, so this method is called & it shows a list of available options to perform this action.So for sending MMS user will have to select "Messaging" option.
Although this works fine for Android version 2.3 but when I run the app on version 4.0.3 then in the list of available options it does not show "Messaging" option.Which is must for sending MMS.
And when I remove the lines
intentEmail.setType("image/jpeg");
intentEmail.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + file.getAbsolutePath()));
then the list shows the "Messaging" option but I can not remove it.
I am really not getting what is the problem with it or may I will have to add something more for version 4.0.3 .
Please help.

Ok I solved the issue.
My new code is
void sendMMS()
{
try
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Drawable drawable = imageProduct.getDrawable();
Bitmap bitmapPicked = ((BitmapDrawable) drawable).getBitmap();
bitmapPicked.compress(CompressFormat.JPEG, 75, bos);
byte[] image = bos.toByteArray();
File file = new File(Environment.getExternalStorageDirectory() + File.separator + "test.jpg");
file.createNewFile();
// write the bytes in file
FileOutputStream fo = new FileOutputStream(file);
fo.write(image);
Log.i(TAG, "image = " + image);
Intent intentMMS = new Intent(Intent.ACTION_SEND);
intentMMS.setType("image/jpg");
intentMMS.setClassName("com.android.mms", "com.android.mms.ui.ComposeMessageActivity");
intentMMS.putExtra("sms_body", messageFacebook);
intentMMS.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
startActivity(intentMMS);
} catch (android.content.ActivityNotFoundException ex)
{
Toast.makeText(this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
ex.printStackTrace();
} catch (Exception e)
{
e.printStackTrace();
}
}

Related

Share image and text with Intent to Whats App

I am trying to share an image from imageview with text caption to whatsApp but the solutions I found online didn't seem to work for me.
View content = findViewById(R.id.posted_house);
content.setDrawingCacheEnabled(true);
Bitmap bitmap = content.getDrawingCache();
File root = Environment.getExternalStorageDirectory();
File cachePath = new File(root.getAbsolutePath() + "/DCIM/Camera/image.jpg");
try
{
root.createNewFile();
FileOutputStream ostream = new FileOutputStream(cachePath);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, ostream);
ostream.close();
}
catch (Exception e)
{
e.printStackTrace();
}
Intent txtIntent = new Intent(android.content.Intent.ACTION_SEND);
txtIntent .setType("image/*");
txtIntent .putExtra("message");
txtIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(cachePath));
startActivity(Intent.createChooser(txtIntent ,"Share"));
}
Here is code for share image and text in whatsapp..
View screenView = rootView.getRootView();
screenView.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(screenView.getDrawingCache());
screenView.setDrawingCacheEnabled(false);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = MediaStore.Images.Media.insertImage(this.getContentResolver(), bitmap, "Title", null);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("image/*");
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "");
intent.putExtra(android.content.Intent.EXTRA_TEXT, "Your message");
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse(path));
try {
startActivity(Intent.createChooser(intent, "Share Screenshot"));
} catch (ActivityNotFoundException e) {
Toast.makeText(this, "No App Available", Toast.LENGTH_SHORT).show();
}

Android Bitmap to File send with Intent

I have this code that gets an image from database as Bitmap and then writes this to a file and sends it with e-mail. This code works great.
I am trying to write this to a textfile that actually shows the picture.
Is this possible?
Do I need to write this to pdf file if I want a file that shows the image?
Here's my code
public void createBild(long x, String pathToFile, String fileName) {
Product product = dbHandler.findProductbyId(x);
Bitmap pic = BitmapFactory.decodeByteArray(dbHandler.fetchSingle(x), 0,
dbHandler.fetchSingle(x).length);
// create a file to write bitmap data
Bitmap bitmap = pic;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.PNG, 0 /* ignored for PNG */, bos);
byte[] bitmapdata = bos.toByteArray();
File f = new File(pathToFile + "/"+fileName+".bmp");
try {
f.createNewFile();
FileOutputStream fos = new FileOutputStream(f);
fos.write(bitmapdata);
fos.flush();
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Uri path = Uri.fromFile(f);
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("image/*");
i.putExtra(Intent.EXTRA_EMAIL, new String[] { "test#live.se" });
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT, "body of email");
i.putExtra(Intent.EXTRA_STREAM, path);
try {
startActivity(Intent.createChooser(i, "Share"));
} catch (android.content.ActivityNotFoundException e) {
Toast.makeText(VisaData.this,
"There are no email clients installed.", Toast.LENGTH_SHORT)
.show();
}
}
Why don't you send it as a .png itself.
intent.setType("image/png");

save screen contents as a image into internal memory and share with social media programatically

Below code will capture the screen and store it in SD card. I want Then it will send this file via sharable apps.I want to store it in internal memory of phone instead but I am unable to do that.Please help me for the same.
WebView view = (WebView) findViewById(R.id.webView1);
#SuppressWarnings("deprecation")
Picture picture = view.capturePicture();
Bitmap b = Bitmap.createBitmap( picture.getWidth(),
picture.getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas( b );
picture.draw( c );
String filePath = Environment.getExternalStorageDirectory()
+ File.separator + "score.png";
File imagePath = new File(filePath);
FileOutputStream fos;
try {
fos = new FileOutputStream(imagePath);
if(fos!=null)
{
b.compress(CompressFormat.PNG, 100, fos);
fos.flush();
fos.close();
}
if(imagePath.exists())
{
sendMail(filePath);
}
else
{
Log.e("fie","file doesnt exist");
}
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
public void sendMail(String path) {
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
//emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
// new String[] { "youremail#website.com" });
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
"My Score in Mock Test");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
"PFA");
emailIntent.setType("image/png");
Uri myUri = Uri.parse("file://" + path);
emailIntent.putExtra(Intent.EXTRA_STREAM, myUri);
startActivity(Intent.createChooser(emailIntent, "share score card..."));
}
I tried to achieve this with below code found on stack overflow but it is not working. This code is not showing any exception when I debug through it but file is not creating to internal memory and so sending is failing.

How to attach image in email from drawable in android

I am attaching an image from drawable folder and sending it in a email.
when I send it from default email client.Image extension(.png) is missing in attachment
and and also the file name is changed itself.
I want t send image with default name(as in drawable) and with .png extension.
this is my code.
Intent email = new Intent(Intent.ACTION_SEND);
email.setType("image/png");
email.putExtra(Intent.EXTRA_EMAIL, new String[] { to });
email.putExtra(Intent.EXTRA_SUBJECT, "Hey! ");
email.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://"+ getPackageName() + "/" + R.drawable.ic_launcher));
startActivity(Intent.createChooser(email, "Sending........"));
Please suggest me what is worng in this code
thanks.
You can only attach an image to mail if the image is located in the SDCARD.
So, you'll need to copy the image to SD and then attach it.
InputStream in = null;
OutputStream out = null;
try
{
in = getResources().openRawResource(R.raw.ic_launcher);
out = new FileOutputStream(new File(Environment.getExternalStorageDirectory(), "image.png"));
copyFile(in, out);
in.close();
in = null;
out.flush();
out.close();
out = null;
}
catch (Exception e)
{
Log.e("tag", e.getMessage());
e.printStackTrace();
}
private void copyFile(InputStream in, OutputStream out) throws IOException
{
byte[] buffer = new byte[1024];
int read;
while ((read = in.read(buffer)) != -1)
{
out.write(buffer, 0, read);
}
}
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("text/html");
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "File attached");
Uri uri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "image.png"));
emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(emailIntent, "Send mail..."));

problem in taking screenshots in android by programmatically

in my app i am taking screenshot of the current screen and save it in sdcard. but in the case screenshot is not saved in sdcard. how to take screen shot and send the captured screen shot in email as attachment. please help me.
my coding:
View v1 = view.getRootView();
v1.setDrawingCacheEnabled(true);
Bitmap bm = v1.getDrawingCache();
try
{
System.out.println("path "+Environment.getExternalStorageDirectory());
FileOutputStream out = new FileOutputStream(Environment.getExternalStorageDirectory()+"/ff");
bm.compress(CompressFormat.PNG, 90, out);
}
catch (Exception e)
{
e.printStackTrace();
}
Intent emailIntent = new Intent(Intent.ACTION_SEND);
Uri U=Uri.parse("file:///sdcard/ff");
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "aabc#gmail.com" });
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, " from ..");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "from the app");
emailIntent.setType("image/png");
// emailIntent.putExtra(android.content.Intent.EXTRA_STREAM,U);
emailIntent.putExtra(Intent.EXTRA_STREAM, U);
startActivity(Intent.createChooser(emailIntent, ""));
please help me.
i solved my problem by replace the try clause coding by
File file = new File(Environment.getExternalStorageDirectory()+"/filmfestival.png");
try
{
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
bitmap.compress(CompressFormat.PNG, 100, ostream);
ostream.close();
}
catch (Exception e)
{
e.printStackTrace();
}

Categories

Resources