I have an application that automatically reads incoming MMS messages.
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'.
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. 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:
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...