1

嗨,我想通过我的应用程序发送彩信。为此,我的代码是

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

当用户点击一个按钮时,这个方法就会被调用,它会显示一个可用选项列表来执行这个操作。所以对于发送彩信,用户必须选择“消息”选项。虽然这适用于 Android 2.3 版,但是当我在 4.0.3 版上运行应用程序时,在可用选项列表中它不显示“消息”选项。这是发送彩信所必须的。

当我删除线条时

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

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

我真的不明白它有什么问题,或者我可能不得不为 4.0.3 版本添加更多内容。

请帮忙。

4

1 回答 1

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();
        }
    }
于 2012-09-27T09:04:49.747 回答