{
import { FileSharer, type ShareFileOptions } from '@byteowls/capacitor-filesharer';
public async shareFile(fileUrl:string, shareFilename:string, contentType: string) {
try {
const copyOfSharedFile = await Filesystem.copy({
from: fileUrl!,
to: shareFilename,
toDirectory: Directory.Data
});
const base64FileContents = await this.readFileAsBase64(copyOfSharedFile );
if(base64FileContents === null || base64FileContents.length === 0){
throw new Error('Error sharing file. Unable to readFileAsBase64');
}
const shareOptions: ShareFileOptions = {filename: shareFilename, contentType:contentType, path:copyOfSharedFile.uri, base64Data:base64FileContents};
await FileSharer.share(shareOptions);
await Filesystem.deleteFile({path: copyOfSharedFile.uri, directory:Directory.Data});
} catch (error) {
const errMsg = <string> error;
if(errMsg == 'USER_CANCELLED'){
toastr.info('Cancelled');
return;
}
throw new Error('Error sharing log file:' + <string> error);
}
}
async readFileAsBase64(file: CopyResult): Promise<string> {
try {
const fileStat = await Filesystem.stat({
path: file.uri,
});
if (!fileStat || !fileStat.size) {
throw new Error ('Error sharing file: file does not exist or is empty.');
}
const fileData = await Filesystem.readFile({ path: file.uri });
if (!fileData || !fileData.data) {
throw new Error('Error sharing file: Unable to read file data.');
}
return fileData.data;//base64
} catch (error) {
const errMsg = <string> error;
throw new Error(errMsg);
}
}
}
Affected Platform(s):
Android
Current Behavior
A sqlite db is copied to a backup file and the backup file is shared. This works. However, when reviewing the Android LogCat is see:
Writing exception to parcel
java.lang.SecurityException: Permission Denial: reading com.byteowls.capacitor.filesharer.FileSharerProvider uri content://com.xxx.yyy.zzz.filesharer.fileprovider/capfilesharer/myLog-20231227-093441.db from pid=14783, uid=1000 requires the provider be exported, or grantUriPermission()
at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:918)
at android.content.ContentProvider.semEnforceReadPermission(ContentProvider.java:836)
at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:712)
at android.content.ContentProvider$Transport.query(ContentProvider.java:251)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:107)
at android.os.Binder.execTransactInternal(Binder.java:1316)
at android.os.Binder.execTransact(Binder.java:1280)
2023-12-27 09:34:43.039 14783-14783 ChooserActivity android:ui W Could not load (content://com.xxx.yyy.zzz.filesharer.fileprovider/capfilesharer/myLog-20231227-093441.db) thumbnail/name for preview. If desired, consider using Intent#createChooser to launch the ChooserActivity, and set your Intent's clipData and flags in accordance with that method's documentation
2023-12-27 09:34:43.044 14502-14521 DatabaseUtils com.xxx.yyy.zzz E Writing exception to parcel
java.lang.SecurityException: Permission Denial: reading com.byteowls.capacitor.filesharer.FileSharerProvider uri content://com.xxx.yyy.zzz.filesharer.fileprovider/capfilesharer/myLog-20231227-093441.db from pid=14783, uid=1000 requires the provider be exported, or grantUriPermission()
at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:918)
at android.content.ContentProvider.semEnforceReadPermission(ContentProvider.java:836)
at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:712)
at android.content.ContentProvider$Transport.query(ContentProvider.java:251)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:107)
at android.os.Binder.execTransactInternal(Binder.java:1316)
at android.os.Binder.execTransact(Binder.java:1280)
Expected Behavior
No errors in logcat.
Sample Code or Sample Application Repo
see above
Reproduction Steps
share a file on Android, review the logcat in Android Studio.
Other Information
I dont think I need to add grantUriPermission in my app... but maybe.
Capacitor version:
Library version:
Your Plugin Configuration
Affected Platform(s):
Current Behavior
A sqlite db is copied to a backup file and the backup file is shared. This works. However, when reviewing the Android LogCat is see: Writing exception to parcel java.lang.SecurityException: Permission Denial: reading com.byteowls.capacitor.filesharer.FileSharerProvider uri content://com.xxx.yyy.zzz.filesharer.fileprovider/capfilesharer/myLog-20231227-093441.db from pid=14783, uid=1000 requires the provider be exported, or grantUriPermission() at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:918) at android.content.ContentProvider.semEnforceReadPermission(ContentProvider.java:836) at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:712) at android.content.ContentProvider$Transport.query(ContentProvider.java:251) at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:107) at android.os.Binder.execTransactInternal(Binder.java:1316) at android.os.Binder.execTransact(Binder.java:1280) 2023-12-27 09:34:43.039 14783-14783 ChooserActivity android:ui W Could not load (content://com.xxx.yyy.zzz.filesharer.fileprovider/capfilesharer/myLog-20231227-093441.db) thumbnail/name for preview. If desired, consider using Intent#createChooser to launch the ChooserActivity, and set your Intent's clipData and flags in accordance with that method's documentation 2023-12-27 09:34:43.044 14502-14521 DatabaseUtils com.xxx.yyy.zzz E Writing exception to parcel java.lang.SecurityException: Permission Denial: reading com.byteowls.capacitor.filesharer.FileSharerProvider uri content://com.xxx.yyy.zzz.filesharer.fileprovider/capfilesharer/myLog-20231227-093441.db from pid=14783, uid=1000 requires the provider be exported, or grantUriPermission() at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:918) at android.content.ContentProvider.semEnforceReadPermission(ContentProvider.java:836) at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:712) at android.content.ContentProvider$Transport.query(ContentProvider.java:251) at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:107) at android.os.Binder.execTransactInternal(Binder.java:1316) at android.os.Binder.execTransact(Binder.java:1280)
Expected Behavior
No errors in logcat.
Sample Code or Sample Application Repo
see above
Reproduction Steps
share a file on Android, review the logcat in Android Studio.
Other Information
I dont think I need to add grantUriPermission in my app... but maybe.