I'm trying to add FileProvider as described in this post:
	
		
			
			
				
					
						
						
To an existing app that I'm trying to bring up to date for newer phones. At a few places in the code, I allow the user to e-mail a file to anyone they wish. And of course if they are SDK 24 or higher, the old way of sharing a file doesn't work.
The phone this is being tested on is Android 8
Current version of b4a is 9.5
The demo, as provided in the post, works on this phone.
I have copied the FileProvider.bas file into my project and added as a module. I added the code into the manifest, added the code to the Starter module, and adjusted my app code based on the btnSendEmail_Click SUB in the sample app. The file being attached is a simple text file.
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
When executing the code, it crashes in Starter.Provider.GetFileURI(strReportName) with the following message:
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
I'm stuck. If anyone has any ideas or pointers I would appreciate the help.
Thanks
			
			[class] FileProvider - share files
					Edit: FileProvider is included as an internal library now. After investigating several issues with the current FileProvider code that you can find in the forum, I decided to make some improvements and implement it in a class.  Starting from Android 7 (API 24) you cannot directly share file uris...
				
				To an existing app that I'm trying to bring up to date for newer phones. At a few places in the code, I allow the user to e-mail a file to anyone they wish. And of course if they are SDK 24 or higher, the old way of sharing a file doesn't work.
The phone this is being tested on is Android 8
Current version of b4a is 9.5
The demo, as provided in the post, works on this phone.
I have copied the FileProvider.bas file into my project and added as a module. I added the code into the manifest, added the code to the Starter module, and adjusted my app code based on the btnSendEmail_Click SUB in the sample app. The file being attached is a simple text file.
			
				B4X:
			
		
		
		    Dim msg As Email
    File.Copy(File.DirRootExternal & "/Inventory", strReportName, Starter.Provider.SharedFolder, strReportName)
    msg.Subject = "Inventory comparison file"
    msg.Attachments.Add(Starter.Provider.GetFileUri(strReportName))
    Dim in As Intent = msg.GetIntent
    in.Flags = 1
    StartActivity(msg.GetIntent)
			
				B4X:
			
		
		
		*** Service (starter) Create ***
Using FileProvider? true
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
No wakelock.
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.debug.Debug.delegate(Debug.java:262)
    at BHCS.Inventory.fileprovider._getfileuri(fileprovider.java:47)
    at BHCS.Inventory.main$ResumableSub_bCExport_Click.resume(main.java:7240)
    at BHCS.Inventory.main._bcexport_click(main.java:7021)
    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:351)
    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 de.donmanfred.IconButtonWrapper$1.onClick(IconButtonWrapper.java:73)
    at android.view.View.performClick(View.java:6274)
    at android.view.View$PerformClick.run(View.java:24859)
    at android.os.Handler.handleCallback(Handler.java:789)
    at android.os.Handler.dispatchMessage(Handler.java:98)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6710)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:770)
Caused by: java.lang.IllegalArgumentException: Failed to find configured root that contains /data/data/BHCS.Inventory/files/shared/Geraghty-Gary.Jewett-Comparison.csv
    at androidx.core.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:744)
    at androidx.core.content.FileProvider.getUriForFile(FileProvider.java:418)
    ... 29 moreI'm stuck. If anyone has any ideas or pointers I would appreciate the help.
Thanks
			
				Last edited: