Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions android/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>android</name>
<comment>Project android created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
<filteredResources>
<filter>
<id>1634215444278</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
13 changes: 13 additions & 0 deletions android/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
arguments=
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
jvm.arguments=
offline.mode=false
override.workspace.settings=true
show.console.view=true
show.executions.view=true
12 changes: 7 additions & 5 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.android.tools.build:gradle:4.0.1'
}
}

android {
compileSdkVersion safeExtGet('compileSdkVersion', 28)
compileSdkVersion safeExtGet('compileSdkVersion', 30)
buildToolsVersion safeExtGet('buildToolsVersion', '28.0.3')
defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', 16)
targetSdkVersion safeExtGet('targetSdkVersion', 28)
targetSdkVersion safeExtGet('targetSdkVersion', 30)
versionCode 1
versionName "1.0"
}
Expand All @@ -41,6 +41,8 @@ android {

dependencies {
implementation "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}"
//compile 'com.squareup.okhttp3:okhttp:+'
//{RNFetchBlob_PRE_0.28_DEPDENDENCY}
implementation "com.squareup.okhttp3:okhttp:${safeExtGet('okhttp', '+')}"
implementation "com.squareup.okhttp3:logging-interceptor:${safeExtGet('okhttp', '+')}"
implementation "com.squareup.okhttp3:okhttp-urlconnection:${safeExtGet('okhttp', '+')}"
// {RNFetchBlob_PRE_0.28_DEPDENDENCY}
}
4 changes: 2 additions & 2 deletions android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Jun 01 10:33:07 BRT 2018
#Fri Aug 07 22:58:34 IST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
9 changes: 5 additions & 4 deletions android/src/main/java/com/RNFetchBlob/RNFetchBlob.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
import com.facebook.react.modules.network.ForwardingCookieHandler;
import com.facebook.react.modules.network.CookieJarContainer;
import com.facebook.react.modules.network.OkHttpClientProvider;
import okhttp3.OkHttpClient;

import okhttp3.JavaNetCookieJar;
import okhttp3.OkHttpClient;

import java.io.File;
import java.util.Map;
Expand Down Expand Up @@ -108,7 +109,7 @@ public void run() {
@ReactMethod
public void actionViewIntent(String path, String mime, final Promise promise) {
try {
Uri uriForFile = FileProvider.getUriForFile(getCurrentActivity(),
Uri uriForFile = FileProvider.getUriForFile(this.getReactApplicationContext(),
this.getReactApplicationContext().getPackageName() + ".provider", new File(path));

if (Build.VERSION.SDK_INT >= 24) {
Expand Down Expand Up @@ -336,7 +337,7 @@ public void df(final Callback callback) {
fsThreadPool.execute(new Runnable() {
@Override
public void run() {
RNFetchBlobFS.df(callback);
RNFetchBlobFS.df(callback, getReactApplicationContext());
}
});
}
Expand Down Expand Up @@ -404,7 +405,7 @@ public void addCompleteDownload (ReadableMap config, Promise promise) {

@ReactMethod
public void getSDCardDir(Promise promise) {
RNFetchBlobFS.getSDCardDir(promise);
RNFetchBlobFS.getSDCardDir(this.getReactApplicationContext(), promise);
}

@ReactMethod
Expand Down
24 changes: 12 additions & 12 deletions android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,16 +252,16 @@ static Map<String, Object> getSystemfolders(ReactApplicationContext ctx) {

res.put("DocumentDir", ctx.getFilesDir().getAbsolutePath());
res.put("CacheDir", ctx.getCacheDir().getAbsolutePath());
res.put("DCIMDir", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath());
res.put("PictureDir", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath());
res.put("MusicDir", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC).getAbsolutePath());
res.put("DownloadDir", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath());
res.put("MovieDir", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES).getAbsolutePath());
res.put("RingtoneDir", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_RINGTONES).getAbsolutePath());
res.put("DCIMDir", ctx.getExternalFilesDir(Environment.DIRECTORY_DCIM).getAbsolutePath());
res.put("PictureDir", ctx.getExternalFilesDir(Environment.DIRECTORY_PICTURES).getAbsolutePath());
res.put("MusicDir", ctx.getExternalFilesDir(Environment.DIRECTORY_MUSIC).getAbsolutePath());
res.put("DownloadDir", ctx.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath());
res.put("MovieDir", ctx.getExternalFilesDir(Environment.DIRECTORY_MOVIES).getAbsolutePath());
res.put("RingtoneDir", ctx.getExternalFilesDir(Environment.DIRECTORY_RINGTONES).getAbsolutePath());
String state;
state = Environment.getExternalStorageState();
if (state.equals(Environment.MEDIA_MOUNTED)) {
res.put("SDCardDir", Environment.getExternalStorageDirectory().getAbsolutePath());
res.put("SDCardDir", ctx.getExternalFilesDir(null).getAbsolutePath());

File externalDirectory = ctx.getExternalFilesDir(null);

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

static public void getSDCardDir(Promise promise) {
static public void getSDCardDir(ReactApplicationContext ctx, Promise promise) {
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
promise.resolve(Environment.getExternalStorageDirectory().getAbsolutePath());
promise.resolve(ctx.getExternalFilesDir(null).getAbsolutePath());
} else {
promise.reject("RNFetchBlob.getSDCardDir", "External storage not mounted");
}
Expand Down Expand Up @@ -986,13 +986,13 @@ static void createFileASCII(String path, ReadableArray data, Promise promise) {
}
}

static void df(Callback callback) {
StatFs stat = new StatFs(Environment.getDataDirectory().getPath());
static void df(Callback callback, ReactApplicationContext ctx) {
StatFs stat = new StatFs(ctx.getFilesDir().getPath());
WritableMap args = Arguments.createMap();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
args.putString("internal_free", String.valueOf(stat.getFreeBytes()));
args.putString("internal_total", String.valueOf(stat.getTotalBytes()));
StatFs statEx = new StatFs(Environment.getExternalStorageDirectory().getPath());
StatFs statEx = new StatFs(ctx.getExternalFilesDir(null).getPath());
args.putString("external_free", String.valueOf(statEx.getFreeBytes()));
args.putString("external_total", String.valueOf(statEx.getTotalBytes()));

Expand Down
21 changes: 15 additions & 6 deletions android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,9 @@ public Response intercept(Chain chain) throws IOException {
clientBuilder.addInterceptor(new Interceptor() {
@Override
public Response intercept(@NonNull Chain chain) throws IOException {
Response originalResponse = null;
try {
Response originalResponse = chain.proceed(req);
originalResponse = chain.proceed(req);
ResponseBody extended;
switch (responseType) {
case KeepInMemory:
Expand Down Expand Up @@ -423,13 +424,21 @@ public Response intercept(@NonNull Chain chain) throws IOException {
}
catch(SocketException e) {
timeout = true;
}
catch (SocketTimeoutException e ){
if (originalResponse != null) {
originalResponse.close();
}
} catch (SocketTimeoutException e) {
timeout = true;
//RNFetchBlobUtils.emitWarningEvent("RNFetchBlob error when sending request : " + e.getLocalizedMessage());
} catch(Exception ex) {

if (originalResponse != null) {
originalResponse.close();
}
//ReactNativeBlobUtilUtils.emitWarningEvent("ReactNativeBlobUtil error when sending request : " + e.getLocalizedMessage());
} catch (Exception ex) {
if (originalResponse != null) {
originalResponse.close();
}
}

return chain.proceed(chain.request());
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import android.provider.DocumentsContract;
import android.provider.MediaStore;
import android.content.ContentUris;
import android.os.Environment;
import android.content.ContentResolver;
import com.RNFetchBlob.RNFetchBlobUtils;
import java.io.File;
Expand All @@ -30,7 +29,7 @@ public static String getRealPathFromURI(final Context context, final Uri uri) {
final String type = split[0];

if ("primary".equalsIgnoreCase(type)) {
return Environment.getExternalStorageDirectory() + "/" + split[1];
return context.getExternalFilesDir(null) + "/" + split[1];
}

// TODO handle non-primary volumes
Expand Down