在Android 4.0.3版中发送彩信的问题

时间:2012-09-27 06:13:52

标签: android mms

您好我想通过我的应用程序发送彩信。因为我的代码是

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

当用户点击按钮时,这个方法被称为&它显示了执行此操作的可用选项列表。因此,对于发送MMS用户,必须选择“消息”选项。  虽然这适用于Android 2.3版但是当我在4.0.3版本上运行应用程序时,然后在可用选项列表中它没有显示“消息”选项。它必须用于发送彩信。

当我删除行

intentEmail.setType("image/jpeg");
intentEmail.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + file.getAbsolutePath()));

然后列表显示“消息”选项,但我无法将其删除。

我真的没有得到它的问题,或者我可能需要为版本4.0.3添加更多内容。

请帮忙。

1 个答案:

答案 0 :(得分:0)

好的,我解决了这个问题。

我的新代码是

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