Skip to content

Commit 56f6069

Browse files
author
Chaitanya Anand
committed
Added support for Android API 29
1 parent 1933faf commit 56f6069

File tree

5 files changed

+25
-30
lines changed

5 files changed

+25
-30
lines changed

android/build.gradle

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ buildscript {
1616
google()
1717
}
1818
dependencies {
19-
classpath 'com.android.tools.build:gradle:3.2.1'
19+
classpath 'com.android.tools.build:gradle:4.0.1'
2020
}
2121
}
2222

2323
android {
24-
compileSdkVersion safeExtGet('compileSdkVersion', 28)
24+
compileSdkVersion safeExtGet('compileSdkVersion', 30)
2525
buildToolsVersion safeExtGet('buildToolsVersion', '28.0.3')
2626
defaultConfig {
2727
minSdkVersion safeExtGet('minSdkVersion', 16)
28-
targetSdkVersion safeExtGet('targetSdkVersion', 28)
28+
targetSdkVersion safeExtGet('targetSdkVersion', 30)
2929
versionCode 1
3030
versionName "1.0"
3131
}
@@ -41,6 +41,6 @@ android {
4141

4242
dependencies {
4343
implementation "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}"
44-
//compile 'com.squareup.okhttp3:okhttp:+'
44+
//implementation 'com.squareup.okhttp3:okhttp:+'
4545
//{RNFetchBlob_PRE_0.28_DEPDENDENCY}
4646
}
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

+6-10
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
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+
import com.squareup.okhttp.OkHttpClient;
28+
2829
import okhttp3.JavaNetCookieJar;
2930

3031
import java.io.File;
@@ -60,18 +61,13 @@ public RNFetchBlob(ReactApplicationContext reactContext) {
6061
RCTContext = reactContext;
6162
reactContext.addActivityEventListener(new ActivityEventListener() {
6263
@Override
63-
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
64+
public void onActivityResult(int requestCode, int resultCode, Intent data) {
6465
if(requestCode == GET_CONTENT_INTENT && resultCode == RESULT_OK) {
6566
Uri d = data.getData();
6667
promiseTable.get(GET_CONTENT_INTENT).resolve(d.toString());
6768
promiseTable.remove(GET_CONTENT_INTENT);
6869
}
6970
}
70-
71-
@Override
72-
public void onNewIntent(Intent intent) {
73-
74-
}
7571
});
7672
}
7773

@@ -108,7 +104,7 @@ public void run() {
108104
@ReactMethod
109105
public void actionViewIntent(String path, String mime, final Promise promise) {
110106
try {
111-
Uri uriForFile = FileProvider.getUriForFile(getCurrentActivity(),
107+
Uri uriForFile = FileProvider.getUriForFile(this.getReactApplicationContext(),
112108
this.getReactApplicationContext().getPackageName() + ".provider", new File(path));
113109

114110
if (Build.VERSION.SDK_INT >= 24) {
@@ -336,7 +332,7 @@ public void df(final Callback callback) {
336332
fsThreadPool.execute(new Runnable() {
337333
@Override
338334
public void run() {
339-
RNFetchBlobFS.df(callback);
335+
RNFetchBlobFS.df(callback, getReactApplicationContext());
340336
}
341337
});
342338
}
@@ -404,7 +400,7 @@ public void addCompleteDownload (ReadableMap config, Promise promise) {
404400

405401
@ReactMethod
406402
public void getSDCardDir(Promise promise) {
407-
RNFetchBlobFS.getSDCardDir(promise);
403+
RNFetchBlobFS.getSDCardDir(this.getReactApplicationContext(), promise);
408404
}
409405

410406
@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/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)