Android Code Snippet VideoRecordApp with FileProvider

Status
Not open for further replies.
Requires Audio library v1.70+: https://www.b4x.com/android/forum/threads/updates-to-internal-libraries.59340/#post-635852

Based on FileProvider example and class: Sharing files from your app with File Provider

B4X:
video.Initialize("video") 'video is a process global VideoRecordApp variable.
Dim folder As String = Starter.Provider.SharedFolder
Dim FileName As String = "1.mp4"
video.Record3(folder, FileName, -1, Starter.Provider.GetFileUri(FileName))
Wait For Video_RecordComplete (Success As Boolean)
If Success Then
   'Example of playing the recorded video
   Dim in As Intent
   in.Initialize(in.ACTION_VIEW, "")
   Starter.Provider.SetFileUriAsIntentData(in, FileName)
   in.SetType("video/*")
   StartActivity(in)
End If
 
Last edited:

Eldad Onojetah

Member
Licensed User
I have tried this for video.Record3(...) and it fails.
What I have done:

1. In my Manifest
B4X:
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,
   <external-files-path name="name" path="shared" /> 
)

2. I have FileProvider v1.0 added to the project
3. In Starter,
B4X:
Provider.Initialze
4. Using your sample code provided above
B4X:
Dim folder As String = Starter.Provider.SharedFolder
Dim FileName As String = "1.mp4"
'videoRecorder initialised elsewhere
videoRecorder.Record3(folder, FileName, -1, Starter.Provider.GetFileUri(File.Combine(folder, FileName)))

I get the following error:
B4X:
** Activity (main) Pause, UserClosed = false **
** Activity (homeactivity) Create, isFirst = true **
** Activity (homeactivity) Resume **
geolocationmanager started
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
FusedLocationProvider1_ConnectionSuccess
(Location) Location[fused 65.966700,-18.533300 acc=4 et=+40m22s373ms alt=15.04444408 {Bundle[mParcelledData.dataSize=52]}]
FusedLocationProvider1_LocationChanged
[GeoCodeInfo=(MyMap) {address_components=[{long_name=13, short_name=13, types=[street_number]}, {long_name=Sunnubraut, short_name=Sunnubraut, types=[route]}, {long_name=Dalvík, short_name=Dalvík, types=[locality, political]}, {long_name=Iceland, short_name=IS, types=[country, political]}], formatted_address=Sunnubraut 13, Dalvík, Iceland, geometry={location={lat=65.9678782, lng=-18.5373444}, location_type=ROOFTOP, viewport={northeast={lat=65.96922718029151, lng=-18.5359954197085}, southwest={lat=65.9665292197085, lng=-18.5386933802915}}}, place_id=ChIJsa_AHMi-0kgRn6RJ1HlXnVQ, plus_code={compound_code=XF97+53 Dalvik, Iceland, global_code=9CQ3XF97+53}, types=[street_address]}, IsInitialized=false, Latitude=65.9667
, Location=Sunnubraut 13, Dalvík, Iceland, LocationOk=true, Longitude=-18.5333
]
registerdevice -> {
  "id": "yt97d0",
  "success": true
}
** Activity (homeactivity) Pause, UserClosed = false **
** Activity (sendreportactivity) Create, isFirst = true **
** Activity (sendreportactivity) Resume **
Error occurred on line: 34 (FileProvider)
java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:131)
    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$2.run(BA.java:370)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6077)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.IllegalArgumentException: Failed to find configured root that contains /data/data/com.ohiritech.app/files/shared/data/user/0/com.ohiritech.app/files/shared/1.mp4
    at android.support.v4.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:739)
    at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:418)
    ... 16 more

I have also tried
B4X:
...
videoRecorder.Record3(folder, FileName, -1, Starter.Provider.GetFileUri(folder, FileName))

The error is similar.

I currently use this same code for recording audio and using the file Chooser and it works file.
 
Status
Not open for further replies.
Top