1

我想将一些文本中的图像附加到 Android 中的 MMS。我在 SO 和 Google 上发现了很多,但仍然没有得到正确的解决方案。我的代码如下:

Intent sendIntent = new Intent(Intent.ACTION_SEND);
            sendIntent.setType("image/png");
            sendIntent.putExtra("sms_body",
                    getResources().getText(R.string.Message));
            // sendIntent.setType("vnd.android-dir/mms-sms");

            Uri mms_uri = Uri.parse("android.resource://"
                    + getPackageName() + "/" + R.drawable.app_logo);

            sendIntent.putExtra(Intent.EXTRA_STREAM, mms_uri.toString());

            startActivity(Intent.createChooser(sendIntent, ""));

请帮助我解决这个问题。

4

1 回答 1

0

你有这方面的运气吗?我尝试了类似的方法,发现

Uri mms_uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.drawable.app_logo);

不是通用的。我设法通过在资产文件夹中复制图像文件并将其转换为文件来做到这一点。你可以这样做:

File f = new File(getCacheDir()+"/app_logo.png");
if (!f.exists()) try {
    InputStream is = getAssets().open("R.drawable.app_logo");
    int size = is.available();
    byte[] buffer = new byte[size];
    is.read(buffer);
    is.close();

    FileOutputStream fos = new FileOutputStream(f);
    fos.write(buffer);
    fos.close();
} catch (Exception e) { throw new RuntimeException(e); }

sharePicture = f.getPath();
于 2013-08-12T20:16:23.313 回答