我想将一些文本中的图像附加到Android中的MMS.I在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, ""));
请帮我解决这个问题。
答案 0 :(得分:0)
你有运气吗?我尝试了类似的方法,并发现
Uri mms_uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.drawable.app_logo);
不是普遍的。我设法通过在assets文件夹中制作图像文件的副本并将其转换为文件来实现。你可以这样做:
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();