Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Android中发送带有图像附件和一些文本的彩信?_Android_Android Intent - Fatal编程技术网

如何在Android中发送带有图像附件和一些文本的彩信?

如何在Android中发送带有图像附件和一些文本的彩信?,android,android-intent,Android,Android Intent,我想在安卓系统中将一些文本中的图像附加到彩信中。我在SO和Google上都找到了很多,但仍然没有找到正确的解决方案。我的代码如下: Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.setType("image/png"); sendIntent.putExtra("sms_body", getResources().getText(

我想在安卓系统中将一些文本中的图像附加到彩信中。我在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, ""));

请帮我解决这个问题。

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

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

您在运行当前代码时遇到任何错误?没有,没有出现任何错误,但我无法附加图像。就是这样。我不知道哪里出错。您能给我一些有关彩信图像附加的建议吗?