Android Question error when i touch to button

jolclov

Member
When I tried to press the camera button to remove the background of the image, I received this error.
B4X:
logging B4XPages events.
** Activity (main) Resume **
Error occurred on line: 33 (FileProvider)
java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
    at b4a.example.fileprovider._getfileuri(fileprovider.java:84)

B4X:
Private Sub btnCaptureImage_Click
    Wait For (chooser.CaptureImage) Complete (Result As MediaChooserResult)
    HandeChooserResult(Result)
End Sub

Private Sub HandeChooserResult (ChooserResult As MediaChooserResult)
    For Each v As B4XView In Root.GetAllViewsRecursive
        If v.Tag Is B4XImageView Then v.Tag.As(B4XImageView).Clear
    Next
    If ChooserResult.Success = False Then Return
    Dim bmp As B4XBitmap = xui.LoadBitmap(ChooserResult.MediaDir, ChooserResult.MediaFile)
  
    'not mandatory but for better performance we will limit the image size.
    If bmp.Width > 2000 Or bmp.Height > 2000 Then bmp = bmp.Resize(2000, 2000, True)
    #if B4A
    If ChooserResult.Mime = "image/jpeg" Then
        bmp = RotateJpegs(ChooserResult, bmp)
    End If
    #end if
  
    ivOriginal.Bitmap = bmp
    ivOrigSmall.Bitmap = bmp
    ivMask.mBase.Alpha = 0.5
    Wait For (SelfieSegmenter.Process(bmp)) Complete (res As SelfieSegmentationResult)
    If res.Success Then
        ivMask.Bitmap = res.ForegroundBitmap
        ivMaskSmall.Bitmap = res.ForegroundBitmap
    End If
End Sub

#if B4A
'code from SimpleMediaManager
Private Sub RotateJpegs(ChooserResult As MediaChooserResult, bmp As B4XBitmap) As B4XBitmap
    Dim in As InputStream = File.OpenInput(ChooserResult.MediaDir, ChooserResult.MediaFile)
    Dim ExifInterface As JavaObject
    ExifInterface.InitializeNewInstance("android.media.ExifInterface", Array(in))
    Dim orientation As Int = ExifInterface.RunMethod("getAttribute", Array("Orientation"))
    bmp = RotateBitmapBasedOnOrientation(bmp, orientation)
    in.Close
    Return bmp
End Sub

Private Sub RotateBitmapBasedOnOrientation (bmp As B4XBitmap, orientation As Int) As B4XBitmap 'ignore
    Select orientation
        Case 3  '180
            bmp = bmp.Rotate(180)
        Case 6 '90
            bmp = bmp.Rotate(90)
        Case 8 '270
            bmp = bmp.Rotate(270)
    End Select
    Return bmp
End Sub
#End If
 

Attachments

  • 1728913136592_SubjectSegmentation.zip
    16.1 KB · Views: 29
Solution
You are missing the MediaChooser manifest editor
Yes... it's solve when add MediaChooser and File Provider to manifest editor

B4X:
'MediaChooser:
SetServiceAttribute(KeepRunningService, android:foregroundServiceType, shortService)





'File Provider
AddApplicationText(
  <provider
  android:name="android.support.v4.content.FileProvider"
  android:authorities="$PACKAGE$.provider"
  android:exported="false"
  android:grantUriPermissions="true">
  <meta-data
  android:name="android.support.FILE_PROVIDER_PATHS"
  android:resource="@xml/provider_paths"/>
  </provider>
)
CreateResource(xml, provider_paths,
   <files-path name="name" path="shared" />
)

jolclov

Member
You are missing the MediaChooser manifest editor
Yes... it's solve when add MediaChooser and File Provider to manifest editor

B4X:
'MediaChooser:
SetServiceAttribute(KeepRunningService, android:foregroundServiceType, shortService)





'File Provider
AddApplicationText(
  <provider
  android:name="android.support.v4.content.FileProvider"
  android:authorities="$PACKAGE$.provider"
  android:exported="false"
  android:grantUriPermissions="true">
  <meta-data
  android:name="android.support.FILE_PROVIDER_PATHS"
  android:resource="@xml/provider_paths"/>
  </provider>
)
CreateResource(xml, provider_paths,
   <files-path name="name" path="shared" />
)
 
Upvote 0
Solution
Top