OCR, FaceRecognition, BarcodeScanner using Google Vision

im getting
Code: Copy
android.os.FileUriExposedException: file:///storage/emulated/0/picture.jpg exposed beyond app through ClipData.Item.getUri()
when i try the text scanner and targeting api 28
i know it is an issue with android 7.0 and above which has a fix in the form but im not sure how do i fix it with this lib :(
It is good that you found this issue.
You can find more information about it on https://stackoverflow.com/questions...tion-file-storage-emulated-0-test-txt-exposed
You have to use FileProvider.
I had a look at the link on the first page of this thread to the github project that this library is based on, and noticed that the author updated his github project to use FileProvider.
I look at the code (of OCR only) and noticed only one change in BuildPicture function:
Code: Copy
private void takePicture() {
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        File photo = new File(Environment.getExternalStorageDirectory(), "picture.jpg");
        imageUri = FileProvider.getUriForFile(MainActivity.this, BuildConfig.APPLICATION_ID + ".provider", photo);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
        startActivityForResult(intent, PHOTO_REQUEST);
}

If DonManfred had his original code he could change it, in this function like this:
Code: Copy
if (Build.VERSION.SDK_INT > 24){
    imageUri = FileProvider.getUriForFile(BA.applicationContext, BA.applicationContext.getPackageName() + ".provider", photo);
}
else{
    imageUri = Uri.fromFile(photo);
}
And the following would have to be added to the manifest:
Code: Copy
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.xml,
   <external-path name="external_files" path="." />
)
Or you could do it yourself using Johan's library based on the same github project https://www.b4x.com/android/forum/threads/ocr-mobilevisiontext.82910/#content
He has provided source code for his library.
 
hello. i have problem with the example file.
It crash when i click on the button.
Code: Copy
android.os.FileUriExposedException: file:///storage/9016-4EF8/picture.jpg exposed beyond app through ClipData.Item.getUri()

After code scan, how can i do copy and paste in a edittext for search?
 
This is a wrap for this github project.

It is basically the same as the one posted by @Johan Schoeman plus facerecognition and Barcodescanner (as of now it is configigured to scan all know formats.)


MobileVision

Author:
Version:
1.51
  • BarcodeDetector
    • Events:
      • onBarcodeResult (success As Boolean, info As String, result As List)
      • Result (info As String, scanresults As List)
    • Functions:
      • decodeBitmapUri (ctx As android.content.Context, uri As android.net.Uri) As android.graphics.Bitmap
      • detect (frame As com.google.android.gms.vision.Frame)
      • Initialize (EventName As String)
      • launchMediaScanIntent
      • receiveFrame (frame As com.google.android.gms.vision.Frame)
      • release
      • scanBitmap (b As android.graphics.Bitmap)
      • setFocus (focus As Int) As Boolean
      • takePicture
    • Properties:
      • isOperational As Boolean [read only]
  • FaceDetector
    • Events:
      • onFaceDetectResult (success As Boolean, result As String)
      • Result (info As String, scanresults As List)
    • Functions:
      • decodeBitmapUri (ctx As android.content.Context, uri As android.net.Uri) As android.graphics.Bitmap
      • detect (frame As com.google.android.gms.vision.Frame)
      • Initialize (EventName As String)
      • launchMediaScanIntent
      • receiveFrame (frame As com.google.android.gms.vision.Frame)
      • release
      • scanBitmap (b As android.graphics.Bitmap)
      • setFocus (focus As Int) As Boolean
      • takePicture
    • Properties:
      • isOperational As Boolean [read only]
  • TextRecognizer
    • Events:
      • onOCRScanResult (success As Boolean, result As String)
      • Result (info As String, blocks As String, lines As String, words As String, scanresults As List)
    • Functions:
      • decodeBitmapUri (ctx As android.content.Context, uri As android.net.Uri) As android.graphics.Bitmap
      • detect (frame As com.google.android.gms.vision.Frame)
      • Initialize (EventName As String)
      • launchMediaScanIntent
      • receiveFrame (frame As com.google.android.gms.vision.Frame)
      • release
      • scanBitmap (b As android.graphics.Bitmap)
      • setFocus (focus As Int) As Boolean
      • takePicture
    • Properties:
      • isOperational As Boolean [read only]
      • Processor As com.google.android.gms.vision.Detector.Processor [write only]

hello, can you help me, this test program I have the following error:

the line with the error is the example itself

Logger conectado a: motorola moto g(6) plus
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Error occurred on line: 72 (Main)
android.os.FileUriExposedException: file:///storage/emulated/0/picture.jpg exposed beyond app through ClipData.Item.getUri()
at android.os.StrictMode.onFileUriExposed(StrictMode.java:1993)
at android.net.Uri.checkFileUriExposed(Uri.java:2379)
at android.content.ClipData.prepareToLeaveProcess(ClipData.java:963)
at android.content.Intent.prepareToLeaveProcess(Intent.java:10227)
at android.content.Intent.prepareToLeaveProcess(Intent.java:10212)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1736)
at android.app.Activity.startActivityForResult(Activity.java:4594)
at android.app.Activity.startActivityForResult(Activity.java:4552)
at anywheresoftware.b4a.BA.startActivityForResult(BA.java:542)
at de.donmanfred.FaceDetectorwrapper.takePicture(FaceDetectorwrapper.java:242)
at b4a.example.main._btnfacedetect_click(main.java:445)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:180)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:6600)
at android.view.View.performClickInternal(View.java:6577)
at android.view.View.access$3100(View.java:781)
at android.view.View$PerformClick.run(View.java:25912)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6923)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:870)
 
android.os.FileUriExposedException: file:///storage/emulated/0/picture.jpg exposed beyond app through ClipData.Item.getUri()

You need to use FileProvider. file-Uris are not allowed anymore.

Please create a new thread in the questionsforum.

Posting to existing threads is a mistake.
 
Hello. Are there any updates for this lib? I cannot get it to work. IsOperational keeps returning FALSE...
 
Back
Top