即使使用工作URI,图像也不会附加到短信
当我按下Share(分享)按钮时,SMS正文进入状态很好,但我无法让图像显示出来。它甚至不像有任何依恋。即使使用工作URI,图像也不会附加到短信
我查看了我的所有代码,它看起来很好,但我不能说我是开发专家,所以我可能会查找一些东西。
有谁知道会发生什么事?
从数据库中获取URI(我知道URI是正确的,因为一个ImageView的正确显示,在此基础上相同的URI):
imageURI = Uri.parse(cursor.getString(cursor.getColumnIndexOrThrow(WineContract.WineEntry.COLUMN_WINE_IMAGE)));
这是我尝试将URI设置为附件:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_shareWine) {
Intent intentShare = new Intent(Intent.ACTION_SENDTO);
intentShare.setData(Uri.parse("smsto:")); // This ensures only SMS apps respond
intentShare.putExtra("sms_body", "The sms body goes here";
//Attaching the image I want into the text:
intentShare.putExtra(intentShare.EXTRA_STREAM, imageURI);
if (intentShare.resolveActivity(getPackageManager()) != null) {
startActivity(intentShare);
}
它区分有帮助,这是我最初是如何获得的URI:
private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Ensure that there's a camera activity to handle the intent
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
}
// Continue only if the File was successfully created
if (photoFile != null) {
photoURI = FileProvider.getUriForFile(this,
"jeremy.com.wineofmine.fileprovider",
photoFile);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
}
}
}
private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
// Save a file: path for use with ACTION_VIEW intents
mCurrentPhotoPath = image.getAbsolutePath();
return image;
}
我固定它通过改变intentShare代码这样:
Intent intentShare = new Intent(Intent.ACTION_SEND);
intentShare.putExtra(intentShare.EXTRA_STREAM, imageURI);
intentShare.setType("image/*");
intentShare.putExtra(Intent.EXTRA_TEXT, "The sms body goes here");
if (intentShare.resolveActivity(getPackageManager()) != null) {
startActivity(intentShare);
}
ModularSynth让我意识到ACTION_SENDTO是行不通的,因为这是唯一的文字。
另一件可能帮助别人的事情是,当我改变为ACTION_SEND时,它只是在第一次放置图像时,没有身体。我也修正了这一点。
而是这行:
intentShare.putExtra("sms_body", "The sms body goes here";
将其替换为:
intentShare.putExtra(Intent.EXTRA_TEXT, "The sms body goes here");
,将让您同时发送的图像和彩信的文字。
呼叫addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
到ACTION_SEND
Intent
调用startActivity()
之前。现在,您正在附加Uri
,但收件人无权阅读该Uri
标识的内容。
我添加了这行代码,但没有解决这个问题。 'intentShare.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);' – andrdoiddev
** S ** MS不交换任何附件。 ** M ** MS。 –