[英]How to send MMS with image attachment and some text in Android?
我想在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, ""));
請幫我解決這個問題。
你有運氣嗎? 我嘗試了類似的方法,發現
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();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.