Skip to content

Commit 94cab1f

Browse files
Ron RadtkeRon Radtke
Ron Radtke
authored and
Ron Radtke
committed
Fixing some permissions
Merge remote-tracking branch 'origin/pulls/620203868/13'
2 parents 1f4210f + e84f259 commit 94cab1f

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

README.md

+32
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,38 @@ RNFetchBlob.config({
566566
.then(...)
567567
```
568568

569+
## React Native developers to access android device path for app bundle
570+
571+
```js
572+
NativeModules.RNFetchBlob.getAppDir((error, path) => {
573+
574+
//here path is your apps directory in mobile device
575+
576+
RNFetchBlob
577+
578+
.config({
579+
addAndroidDownloads : {
580+
useDownloadManager : true, // <-- this is the only thing required
581+
// Optional, override notification setting (default to true)
582+
notification : false,
583+
// Optional, but recommended since android DownloadManager will fail when
584+
// the url does not contains a file extension, by default the mime type will be text/plain
585+
mime : 'text/plain',
586+
description : 'File downloaded by download manager.'
587+
}
588+
})
589+
.fetch('GET', 'http://example.com/file/somefile')
590+
.then((resp) => {
591+
// the path of downloaded file
592+
resp.path()
593+
})
594+
})
595+
```
596+
In case error appears or app crash just go to
597+
AndroidMaifest.xml file and add
598+
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
599+
600+
569601
**Open Downloaded File with Intent**
570602

571603
This is a new feature added in `0.9.0` if you're going to open a file path using official [Linking](https://facebook.github.io/react-native/docs/linking.html) API that might not work as expected, also, if you're going to install an APK in `Downloads` app, that will not function too. As an alternative, you can try `actionViewIntent` API, which will send an ACTION_VIEW intent for you which uses the given `MIME` type.

android/src/main/AndroidManifest.xml

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020

2121
<!-- Required to read and write the expansion files on shared storage -->
2222
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
23+
24+
<!-- Required to disable download notification -->
25+
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
2326

2427
<application android:label="@string/app_name">
2528

android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,22 @@ static public void getSDCardApplicationDir(ReactApplicationContext ctx, Promise
297297
promise.reject("RNFetchBlob.getSDCardApplicationDir", "External storage not mounted");
298298
}
299299
}
300-
300+
// method for android
301+
public static String getSDCardApplicationDir(ReactApplicationContext ctx) {
302+
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
303+
try {
304+
final String path = ctx.getExternalFilesDir(null).getParentFile().getAbsolutePath();
305+
return path;
306+
} catch (Exception e) {
307+
e.printStackTrace();
308+
return "";
309+
}
310+
} else {
311+
Log.d("getSDCardApplicationDir","media is not mounted");
312+
return "";
313+
}
314+
}
315+
301316
/**
302317
* Static method that returns a temp file path
303318
* @param taskId An unique string for identify

0 commit comments

Comments
 (0)