Hi Erel
I am using ContentResolver and trying to access data from MMS that stored in phone. I can access the data from MMS parts, but I can not load it successfully into the ImageView. I already spent 2 - 3 days on it and cannot find out why I got error. Please help (see error quoted below).
Error log is as follow:
Edit: I attached herewith the test project. Please don't forget to get at least any 1 MMS received in your inbox (with sample image) before testing.
I also attached the screenshot of the folder where we can find the data of MMS, we can see that the file does exist there...
I am using ContentResolver and trying to access data from MMS that stored in phone. I can access the data from MMS parts, but I can not load it successfully into the ImageView. I already spent 2 - 3 days on it and cannot find out why I got error. Please help (see error quoted below).
B4X:
Sub Button1_Click
Dim InboxUri As Uri
InboxUri.Parse("content://mms/inbox")
Dim cursor1 As Cursor = cr.Query(InboxUri, Null, "", Null, "")
Dim mmsId As Int = 0
For i = 0 To cursor1.RowCount - 1
cursor1.Position = i
'// To get the id of the very last MMS in the database, or any MMS just to test
If i = 0 Then
mmsId = cursor1.GetString("_id")
End If
Next
Log("The MMS Id is = " & mmsId)
cursor1.Close
InboxUri.Parse("content://mms/part")
Dim cursor2 As Cursor = cr.Query(InboxUri, Null, "mid = ?", Array As String(mmsId), "")
Dim data() As Byte
For i = 0 To cursor2.RowCount - 1
cursor2.Position = i
If cursor2.GetString("ct").Contains("image") Then
'datapath = cursor2.GetString("_data")
data = cursor2.GetBlob("_data")
End If
Next
cursor2.Close
Dim InputStream1 As InputStream
InputStream1.InitializeFromBytesArray(data, 0, data.Length)
'Read stream into image view
Dim Bitmap1 As Bitmap
Bitmap1.Initialize2(InputStream1) '// <-- ERROR IS HERE (WITH DEBUG MODE)
InputStream1.Close
ImageView1.Bitmap = Bitmap1
End Sub
Error log is as follow:
The MMS Id is = 92
main_button1_click (B4A line: 104)
Bitmap1.Initialize2(InputStream1)
java.lang.RuntimeException: Error loading bitmap.
at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.Initialize2(CanvasWrapper.java:521)
at b4a.example.main._button1_click(main.java:387)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:63)
at android.view.View.performClick(View.java:3574)
at android.view.View$PerformClick.run(View.java:14293)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4441)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
at dalvik.system.NativeStart.main(Native Method)
Edit: I attached herewith the test project. Please don't forget to get at least any 1 MMS received in your inbox (with sample image) before testing.
I also attached the screenshot of the folder where we can find the data of MMS, we can see that the file does exist there...
Attachments
Last edited: