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();
}
}