Example was updated based on FileProvider class: https://www.b4x.com/android/forum/threads/class-fileprovider-share-files.97865/
See the above link if you are interested in sharing files from your app.
This tutorial explains the steps required to implement a file picker that other applications can use to select files or resources.
		
		
	
	
		
	 
		
	 
		
	
Starting from Android 7 - Nougat,it is not possible to share a file directly (file:// uri). It will result with a FileUriExposedException. This is relevant even if you don't set the targetSdkVersion to 24.
The solution is to use FileProvider from Android support library.
The steps required are:
1. Add an intent filter that will tell the OS that your app allows choosing content:
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
3. When the relevant activity is resumed it needs to check the starting intent type. If it is an android.intent.action.GET_CONTENT intent then it should allow the user to select the resource.
4. The resource is copied to the "shared" folder and a Uri is created and returned to the calling app.
See the attached example.
Tips:
- Make sure to run the app in release mode as the process might be killed when it is in the background.
- This solution is compatible with Android 4+ devices.
			
			See the above link if you are interested in sharing files from your app.
This tutorial explains the steps required to implement a file picker that other applications can use to select files or resources.
Starting from Android 7 - Nougat,it is not possible to share a file directly (file:// uri). It will result with a FileUriExposedException. This is relevant even if you don't set the targetSdkVersion to 24.
The solution is to use FileProvider from Android support library.
The steps required are:
1. Add an intent filter that will tell the OS that your app allows choosing content:
			
				B4X:
			
		
		
		'manifest editor.
'FilePicker is the name of the activity.
AddActivityText(FilePicker,
<intent-filter>
  <action android:name="android.intent.action.PICK" />
  <category android:name="android.intent.category.DEFAULT" />
  <data android:mimeType="image/*" />
</intent-filter>
<intent-filter>
  <action android:name="android.intent.action.GET_CONTENT" />
  <category android:name="android.intent.category.DEFAULT" />
  <category android:name="android.intent.category.OPENABLE" />
  <data android:mimeType="image/*" />
</intent-filter>
)
	3. When the relevant activity is resumed it needs to check the starting intent type. If it is an android.intent.action.GET_CONTENT intent then it should allow the user to select the resource.
4. The resource is copied to the "shared" folder and a Uri is created and returned to the calling app.
See the attached example.
Tips:
- Make sure to run the app in release mode as the process might be killed when it is in the background.
- This solution is compatible with Android 4+ devices.
Attachments
			
				Last edited: