Issue on sending MMS in Android version 4.0.3

戏子无情 提交于 2019-12-11 07:57:11

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/12615136/issue-on-sending-mms-in-android-version-4-0-3

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!