mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-02-22 23:08:07 +01:00
FIX: open & save files to file system
This commit is contained in:
parent
146138cba5
commit
92ea58dc85
3 changed files with 20 additions and 7 deletions
|
@ -68,7 +68,7 @@
|
|||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:label="@string/app_name"
|
||||
android:launchMode="singleInstance"
|
||||
android:launchMode="singleTop"
|
||||
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
|
||||
android:windowSoftInputMode="adjustResize"
|
||||
android:exported="true">
|
||||
|
|
|
@ -10,7 +10,7 @@ import alert from '../components/Alert';
|
|||
import { readFile } from './react-native-bw-file-access';
|
||||
const LocalQRCode = require('@remobile/react-native-qrcode-local-image');
|
||||
|
||||
const writeFileAndExportToAndroidDestionation = async ({ filename, contents, destinationLocalizedString, destination }) => {
|
||||
const _writeFileAndExportToAndroidDestionation = async ({ filename, contents, destinationLocalizedString, destination }) => {
|
||||
const granted = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE, {
|
||||
title: loc.send.permission_storage_title,
|
||||
message: loc.send.permission_storage_message,
|
||||
|
@ -18,11 +18,24 @@ const writeFileAndExportToAndroidDestionation = async ({ filename, contents, des
|
|||
buttonNegative: loc._.cancel,
|
||||
buttonPositive: loc._.ok,
|
||||
});
|
||||
|
||||
// In Android 13 no WRITE_EXTERNAL_STORAGE permission is needed
|
||||
// @see https://stackoverflow.com/questions/76311685/permissionandroid-request-always-returns-never-ask-again-without-any-prompt-r
|
||||
if (granted === PermissionsAndroid.RESULTS.GRANTED || Platform.Version >= 33) {
|
||||
const filePath = destination + `/${filename}`;
|
||||
try {
|
||||
await RNFS.writeFile(filePath, contents);
|
||||
alert(loc.formatString(loc._.file_saved, { filePath: filename, destination: destinationLocalizedString }));
|
||||
console.log(`file saved to ${filePath}`);
|
||||
await Share.open({
|
||||
url: 'file://' + filePath,
|
||||
saveToFiles: isDesktop,
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
})
|
||||
.finally(() => {
|
||||
RNFS.unlink(filePath);
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
alert(e.message);
|
||||
|
@ -57,11 +70,11 @@ const writeFileAndExport = async function (filename, contents) {
|
|||
RNFS.unlink(filePath);
|
||||
});
|
||||
} else if (Platform.OS === 'android') {
|
||||
await writeFileAndExportToAndroidDestionation({
|
||||
await _writeFileAndExportToAndroidDestionation({
|
||||
filename,
|
||||
contents,
|
||||
destinationLocalizedString: loc._.downloads_folder,
|
||||
destination: RNFS.DownloadDirectoryPath,
|
||||
destination: RNFS.DocumentDirectoryPath,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
@ -42,7 +42,7 @@ export default class Selftest extends Component {
|
|||
}
|
||||
|
||||
onPressSaveToStorage = () => {
|
||||
fs.writeFileAndExport('bluewallet-storagesave-test.txt', 'Success');
|
||||
fs.writeFileAndExport('bluewallet-storagesave-test.txt', 'Success on ' + new Date().toUTCString());
|
||||
};
|
||||
|
||||
onPressImportDocument = async () => {
|
||||
|
@ -318,7 +318,7 @@ export default class Selftest extends Component {
|
|||
<BlueSpacing20 />
|
||||
<Button title="Test Save to Storage" onPress={this.onPressSaveToStorage} />
|
||||
<BlueSpacing20 />
|
||||
<Button title="Test Save to File Import" onPress={this.onPressImportDocument} />
|
||||
<Button title="Test File Import" onPress={this.onPressImportDocument} />
|
||||
</ScrollView>
|
||||
</BlueCard>
|
||||
</SafeArea>
|
||||
|
|
Loading…
Add table
Reference in a new issue