Skip to content

Commit 8876c3c

Browse files
authored
Merge pull request #646 from chaits98/master
Added support for Android API 29 and API 30
2 parents dfc6806 + eff92b1 commit 8876c3c

File tree

8 files changed

+83
-31
lines changed

8 files changed

+83
-31
lines changed

android/.project

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>android</name>
4+
<comment>Project android created by Buildship.</comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
16+
</natures>
17+
<filteredResources>
18+
<filter>
19+
<id>1634215444278</id>
20+
<name></name>
21+
<type>30</type>
22+
<matcher>
23+
<id>org.eclipse.core.resources.regexFilterMatcher</id>
24+
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
25+
</matcher>
26+
</filter>
27+
</filteredResources>
28+
</projectDescription>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
arguments=
2+
auto.sync=false
3+
build.scans.enabled=false
4+
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
5+
connection.project.dir=
6+
eclipse.preferences.version=1
7+
gradle.user.home=
8+
java.home=/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
9+
jvm.arguments=
10+
offline.mode=false
11+
override.workspace.settings=true
12+
show.console.view=true
13+
show.executions.view=true

android/build.gradle

+7-5
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ buildscript {
1515
google()
1616
}
1717
dependencies {
18-
classpath 'com.android.tools.build:gradle:3.2.1'
18+
classpath 'com.android.tools.build:gradle:4.0.1'
1919
}
2020
}
2121

2222
android {
23-
compileSdkVersion safeExtGet('compileSdkVersion', 28)
23+
compileSdkVersion safeExtGet('compileSdkVersion', 30)
2424
buildToolsVersion safeExtGet('buildToolsVersion', '28.0.3')
2525
defaultConfig {
2626
minSdkVersion safeExtGet('minSdkVersion', 16)
27-
targetSdkVersion safeExtGet('targetSdkVersion', 28)
27+
targetSdkVersion safeExtGet('targetSdkVersion', 30)
2828
versionCode 1
2929
versionName "1.0"
3030
}
@@ -40,6 +40,8 @@ android {
4040

4141
dependencies {
4242
implementation "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}"
43-
//compile 'com.squareup.okhttp3:okhttp:+'
44-
//{RNFetchBlob_PRE_0.28_DEPDENDENCY}
43+
implementation "com.squareup.okhttp3:okhttp:${safeExtGet('okhttp', '+')}"
44+
implementation "com.squareup.okhttp3:logging-interceptor:${safeExtGet('okhttp', '+')}"
45+
implementation "com.squareup.okhttp3:okhttp-urlconnection:${safeExtGet('okhttp', '+')}"
46+
// {RNFetchBlob_PRE_0.28_DEPDENDENCY}
4547
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Fri Jun 01 10:33:07 BRT 2018
1+
#Fri Aug 07 22:58:34 IST 2020
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-bin.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424
import com.facebook.react.modules.network.ForwardingCookieHandler;
2525
import com.facebook.react.modules.network.CookieJarContainer;
2626
import com.facebook.react.modules.network.OkHttpClientProvider;
27-
import okhttp3.OkHttpClient;
27+
2828
import okhttp3.JavaNetCookieJar;
29+
import okhttp3.OkHttpClient;
2930

3031
import java.io.File;
3132
import java.util.Map;
@@ -108,7 +109,7 @@ public void run() {
108109
@ReactMethod
109110
public void actionViewIntent(String path, String mime, final Promise promise) {
110111
try {
111-
Uri uriForFile = FileProvider.getUriForFile(getCurrentActivity(),
112+
Uri uriForFile = FileProvider.getUriForFile(this.getReactApplicationContext(),
112113
this.getReactApplicationContext().getPackageName() + ".provider", new File(path));
113114

114115
// Create the intent with data and type
@@ -331,7 +332,7 @@ public void df(final Callback callback) {
331332
fsThreadPool.execute(new Runnable() {
332333
@Override
333334
public void run() {
334-
RNFetchBlobFS.df(callback);
335+
RNFetchBlobFS.df(callback, getReactApplicationContext());
335336
}
336337
});
337338
}
@@ -399,7 +400,7 @@ public void addCompleteDownload (ReadableMap config, Promise promise) {
399400

400401
@ReactMethod
401402
public void getSDCardDir(Promise promise) {
402-
RNFetchBlobFS.getSDCardDir(promise);
403+
RNFetchBlobFS.getSDCardDir(this.getReactApplicationContext(), promise);
403404
}
404405

405406
@ReactMethod

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

+12-12
Original file line numberDiff line numberDiff line change
@@ -252,16 +252,16 @@ static Map<String, Object> getSystemfolders(ReactApplicationContext ctx) {
252252

253253
res.put("DocumentDir", ctx.getFilesDir().getAbsolutePath());
254254
res.put("CacheDir", ctx.getCacheDir().getAbsolutePath());
255-
res.put("DCIMDir", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath());
256-
res.put("PictureDir", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath());
257-
res.put("MusicDir", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC).getAbsolutePath());
258-
res.put("DownloadDir", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath());
259-
res.put("MovieDir", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES).getAbsolutePath());
260-
res.put("RingtoneDir", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_RINGTONES).getAbsolutePath());
255+
res.put("DCIMDir", ctx.getExternalFilesDir(Environment.DIRECTORY_DCIM).getAbsolutePath());
256+
res.put("PictureDir", ctx.getExternalFilesDir(Environment.DIRECTORY_PICTURES).getAbsolutePath());
257+
res.put("MusicDir", ctx.getExternalFilesDir(Environment.DIRECTORY_MUSIC).getAbsolutePath());
258+
res.put("DownloadDir", ctx.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath());
259+
res.put("MovieDir", ctx.getExternalFilesDir(Environment.DIRECTORY_MOVIES).getAbsolutePath());
260+
res.put("RingtoneDir", ctx.getExternalFilesDir(Environment.DIRECTORY_RINGTONES).getAbsolutePath());
261261
String state;
262262
state = Environment.getExternalStorageState();
263263
if (state.equals(Environment.MEDIA_MOUNTED)) {
264-
res.put("SDCardDir", Environment.getExternalStorageDirectory().getAbsolutePath());
264+
res.put("SDCardDir", ctx.getExternalFilesDir(null).getAbsolutePath());
265265

266266
File externalDirectory = ctx.getExternalFilesDir(null);
267267

@@ -276,9 +276,9 @@ static Map<String, Object> getSystemfolders(ReactApplicationContext ctx) {
276276
return res;
277277
}
278278

279-
static public void getSDCardDir(Promise promise) {
279+
static public void getSDCardDir(ReactApplicationContext ctx, Promise promise) {
280280
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
281-
promise.resolve(Environment.getExternalStorageDirectory().getAbsolutePath());
281+
promise.resolve(ctx.getExternalFilesDir(null).getAbsolutePath());
282282
} else {
283283
promise.reject("RNFetchBlob.getSDCardDir", "External storage not mounted");
284284
}
@@ -986,13 +986,13 @@ static void createFileASCII(String path, ReadableArray data, Promise promise) {
986986
}
987987
}
988988

989-
static void df(Callback callback) {
990-
StatFs stat = new StatFs(Environment.getDataDirectory().getPath());
989+
static void df(Callback callback, ReactApplicationContext ctx) {
990+
StatFs stat = new StatFs(ctx.getFilesDir().getPath());
991991
WritableMap args = Arguments.createMap();
992992
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
993993
args.putString("internal_free", String.valueOf(stat.getFreeBytes()));
994994
args.putString("internal_total", String.valueOf(stat.getTotalBytes()));
995-
StatFs statEx = new StatFs(Environment.getExternalStorageDirectory().getPath());
995+
StatFs statEx = new StatFs(ctx.getExternalFilesDir(null).getPath());
996996
args.putString("external_free", String.valueOf(statEx.getFreeBytes()));
997997
args.putString("external_total", String.valueOf(statEx.getTotalBytes()));
998998

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

+15-6
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,9 @@ public Response intercept(Chain chain) throws IOException {
392392
clientBuilder.addInterceptor(new Interceptor() {
393393
@Override
394394
public Response intercept(@NonNull Chain chain) throws IOException {
395+
Response originalResponse = null;
395396
try {
396-
Response originalResponse = chain.proceed(req);
397+
originalResponse = chain.proceed(req);
397398
ResponseBody extended;
398399
switch (responseType) {
399400
case KeepInMemory:
@@ -423,13 +424,21 @@ public Response intercept(@NonNull Chain chain) throws IOException {
423424
}
424425
catch(SocketException e) {
425426
timeout = true;
426-
}
427-
catch (SocketTimeoutException e ){
427+
if (originalResponse != null) {
428+
originalResponse.close();
429+
}
430+
} catch (SocketTimeoutException e) {
428431
timeout = true;
429-
//RNFetchBlobUtils.emitWarningEvent("RNFetchBlob error when sending request : " + e.getLocalizedMessage());
430-
} catch(Exception ex) {
431-
432+
if (originalResponse != null) {
433+
originalResponse.close();
434+
}
435+
//ReactNativeBlobUtilUtils.emitWarningEvent("ReactNativeBlobUtil error when sending request : " + e.getLocalizedMessage());
436+
} catch (Exception ex) {
437+
if (originalResponse != null) {
438+
originalResponse.close();
439+
}
432440
}
441+
433442
return chain.proceed(chain.request());
434443
}
435444
});

android/src/main/java/com/RNFetchBlob/Utils/PathResolver.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import android.provider.DocumentsContract;
99
import android.provider.MediaStore;
1010
import android.content.ContentUris;
11-
import android.os.Environment;
1211
import android.content.ContentResolver;
1312
import com.RNFetchBlob.RNFetchBlobUtils;
1413
import java.io.File;
@@ -30,7 +29,7 @@ public static String getRealPathFromURI(final Context context, final Uri uri) {
3029
final String type = split[0];
3130

3231
if ("primary".equalsIgnoreCase(type)) {
33-
return Environment.getExternalStorageDirectory() + "/" + split[1];
32+
return context.getExternalFilesDir(null) + "/" + split[1];
3433
}
3534

3635
// TODO handle non-primary volumes

0 commit comments

Comments
 (0)