1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-29 22:48:10 +02:00

Android: Fix file system sync issues (#6943)

This commit is contained in:
javad mnjd
2022-10-23 16:30:27 +03:30
committed by GitHub
parent 7129c0c14e
commit 5324f39561
7 changed files with 26 additions and 48 deletions

View File

@@ -84,6 +84,7 @@
android:configChanges="orientation"
android:label="@string/app_name"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:theme="@style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.SEND" />

View File

@@ -24,9 +24,6 @@ import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.ViewManager;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -46,13 +43,9 @@ public class SharePackage implements ReactPackage {
}
public static class ShareModule extends ReactContextBaseJavaModule implements ActivityEventListener {
private final String cacheDir;
// when refactoring the `shareDirName` make sure to refactor the dir name in `ShareUtils.ts`
private static String shareDirName = "sharedFiles";
ShareModule(@NonNull ReactApplicationContext reactContext) {
super(reactContext);
cacheDir = reactContext.getCacheDir().getAbsolutePath();
reactContext.addActivityEventListener(this);
}
@@ -146,39 +139,7 @@ public class SharePackage implements ReactPackage {
mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
}
Uri copiedUri = null;
try {
String shareFolderPath = cacheDir + "/" + shareDirName;
String filepath = shareFolderPath + "/" + name;
File file = new File(filepath);
copiedUri = Uri.fromFile(file);
if (new File(shareFolderPath).mkdirs()) {
try (InputStream inStream =
contentResolver.openInputStream(uri);
OutputStream outStream =
contentResolver.openOutputStream(copiedUri, "wt");
) {
byte[] buffer = new byte[1024 * 4];
int length;
while ((length = inStream.read(buffer)) > 0) {
outStream.write(buffer, 0, length);
}
}
} else {
throw new IOException("Cannot create sharedFiles directory in cacheDir");
}
} catch (Exception e) {
e.printStackTrace();
copiedUri = null;
}
if (copiedUri != null) {
imageData.putString("uri", copiedUri.toString());
} else {
imageData.putString("uri", uri.toString());
}
imageData.putString("uri", uri.toString());
imageData.putString("name", name);
imageData.putString("mimeType", mimeType);
return imageData;