简体   繁体   English

如何在DELPHI XE8中从MMS打开图像

[英]How to open image from MMS in DELPHI XE8

I have an application that automatically reads incoming MMS messages. 我有一个可以自动读取传入MMS消息的应用程序。

When he delivers a message with an attachment (picture) so I get the directory where the image is saved: 当他发送带有附件的邮件(图片)时,我得到了保存图片的目录:

.
.
.
uri:= StrToJURI('content://mms/part');
uriQuery:= StringToJString('mid = 122');
cursor:= SharedActivity.getContentResolver.query(uri, nil, uriQuery, nil, nil);
imgPath:= JStringToString(cursor.getString(cursor.getColumnIndex(StringToJString('_data'))));
.
.
.

imgPath is for example: ' /data/data/com.android.providers.telephony/app_parts/PART_1440873132846_image.jpeg '. imgPath例如:“ /data/data/com.android.providers.telephony/app_parts/PART_1440873132846_image.jpeg ”。

When I try to open this file it reports an error: ' Cannot open file - Permission denied '. 当我尝试打开此文件时,报告错误:' 无法打开文件-权限被拒绝 '。

Someone advise me how to open this file (picture from MMS message)? 有人建议我如何打开此文件(彩信中的图片)?

You are trying to open a file that belongs to another app. 您正在尝试打开属于另一个应用程序的文件。 Android will not usually allow that, unless the other app explicitly shares the file. 除非其他应用明确共享文件,否则Android通常不允许这样做。 Which, in this case, it is apparently not doing. 在这种情况下,显然没有这样做。

What you can try instead is using another content: URL to access the file based on its ID within the MMS message, rather than its actual file name: 您可以尝试使用的是其他content: URL根据MMS消息中的ID(而不是实际文件名)访问文件:

uri := StrToJURI('content://mms/part');
uriQuery := StringToJString('mid = 122');
cursor := SharedActivity.getContentResolver.query(uri, nil, uriQuery, nil, nil);
partID := StringToString(cursor.getString(cursor.getColumnIndex(StringToJString('_id'))));

uri := StrToJURI('content://mms/part/' + partID);
is := SharedActiviy.getContentResolver.openInputStream(uri); // returns a JInputStream 
try
  bitmap := TJBitmapFactory.JavaClass.decodeStream(is); // returns a JBitmap
finally
  is.close;
end;
// use bitmap as needed...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM