Android Question Need to get Bmp from content URI

Steini1980

Active Member
Licensed User
Longtime User
Could someone help me implementing this Java code in my B4A Project:

B4X:
InputStream istr = contentResolver.openInputStream(uri);
BufferedInputStream buf_istr = new BufferedInputStream(istr, 8192);
Bitmap bm = BitmapFactory.decodeStream(buf_istr);

B4A ContentResolver doesn't supports the method openInputStream(uri)
And the ContentProvider doesn't results TableData, it results the Bitmap directly.
 

Steini1980

Active Member
Licensed User
Longtime User
In the original App I handle this via Try/Catch, but the exception does always breaks here and the customer can't export images from App to the ERP solution.
It's important to solve the problem. On development device it works proberly, but on customer device some users getting always this error. If it's not possible to read the logs on runtime, I hope the customer will ship me his device as parcel, so I can connect the device on the development environment and debug.
 
Upvote 0

Steini1980

Active Member
Licensed User
Longtime User
I think the're no security restrictions to allow/disallow the communication between apps. I have developed the interface between apps on close collaboration with the developer. It seems that some images are exportable, but not all. The error is very odd, If I request an invalid ID the app should deliver dummy data but not NULL.
 
Upvote 0

Steini1980

Active Member
Licensed User
Longtime User
Now I have the customers Tablet here for Debug, here the results of the Cue Stack:

B4X:
java.lang.NullPointerException
    at android.os.Parcel.readException(Parcel.java:1471)
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:185)
    at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:148)
    at android.content.ContentProviderProxy.openTypedAssetFile(ContentProviderNative.java:682)
    at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1073)
    at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:913)
    at android.content.ContentResolver.openInputStream(ContentResolver.java:638)
    at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:206)
    at b4a.dms.poellath.datainterchange._projektexport(datainterchange.java:2266)
    at b4a.dms.poellath.datainterchange._button2_click(datainterchange.java:697)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:174)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:162)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:158)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:66)
    at android.view.View.performClick(View.java:4637)
    at android.view.View$PerformClick.run(View.java:19422)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5479)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
    at dalvik.system.NativeStart.main(Native Method)

I get 90% of the Data without any problems, but the're a kind of images which causes this NullPointerException.
But the Data of both Apps seems good. :confused::mad:
Ideas?!?

There is another Method to Open the Image via Intent for Edit, this works fine!
Only the Data export causes the failure:
B4X:
Sub ImageMeterOpenEdit(Dateiname As String)
  Dim In As Intent
  'In.Initialize(In.ACTION_SEND,"")
  In.Initialize("","")
  In.SetComponent("de.dirkfarin.imagemeterpro/de.dirkfarin.imagemeter.lib.MeasureActivity")
  In.PutExtra("de.dirkfarin.imagemeter.image_id",getImageIdByFilename(Dateiname))
  In.PutExtra("de.dirkfarin.imagemeter.folder_id",2)
  Log("Öffne Imagemeter ID: "& getImageIdByFilename(Dateiname) &" / "& Dateiname)
  StartActivity(In)
End Sub
 
Upvote 0

Steini1980

Active Member
Licensed User
Longtime User
Here the Code again:
B4X:
Sub Button1_Click
  Dim url As String
  Dim LongVal As Long
  Dim dialog As InputDialog
  dialog.InputType = dialog.INPUT_TYPE_NUMBERS
  dialog.Show("ImageMeter Image ID","Eingabe","OK","","",Null)
  If dialog.Response = DialogResponse.POSITIVE Then

      LongVal = dialog.Input
      If LongVal <> -1 Then  
        url = "content://de.dirkfarin.imagemeterpro/image/anno/" & LongVal
        File.Delete(File.DirDefaultExternal, "test_"& LongVal &".jpg")
        Dim jo As JavaObject
        jo.InitializeStatic("anywheresoftware.b4a.objects.streams.File")
        Dim In As InputStream = File.OpenInput(jo.GetField("ContentDir"), url)
        Dim bmp As Bitmap
        bmp.Initialize2(In)
        In.Close
        Dim out As OutputStream
        out = File.OpenOutput(File.DirDefaultExternal, "test_"& LongVal &".jpg",False)
        bmp.WriteToStream(out,80,"JPEG")
        out.Close
        ImageView1.Bitmap = LoadBitmap(File.DirDefaultExternal,"test_"& LongVal &".jpg")
      End If
  End If
End Sub

This Line causes the Error:
Dim In As InputStream = File.OpenInput(jo.GetField("ContentDir"), url)
 
Upvote 0

Steini1980

Active Member
Licensed User
Longtime User
I have checked the url in Debugger and it seems good. If the LongVal isn't correct, the ContentProviders delivers an Dummy image with Text "Cannot find image", so I get in each case an image as result from ImageMeter.
 
Upvote 0
Top