mirror of
https://github.com/deltachat/deltachat-android.git
synced 2025-10-05 02:29:24 +02:00
Initial commit 🌱
This commit is contained in:
commit
b1a00a03d2
2659 changed files with 184218 additions and 0 deletions
41
src/org/thoughtcrime/securesms/util/MemoryFileUtil.java
Normal file
41
src/org/thoughtcrime/securesms/util/MemoryFileUtil.java
Normal file
|
@ -0,0 +1,41 @@
|
|||
package org.thoughtcrime.securesms.util;
|
||||
|
||||
|
||||
import android.os.Build;
|
||||
import android.os.MemoryFile;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class MemoryFileUtil {
|
||||
|
||||
public static ParcelFileDescriptor getParcelFileDescriptor(MemoryFile file) throws IOException {
|
||||
try {
|
||||
Method method = MemoryFile.class.getDeclaredMethod("getFileDescriptor");
|
||||
FileDescriptor fileDescriptor = (FileDescriptor) method.invoke(file);
|
||||
|
||||
Field field = fileDescriptor.getClass().getDeclaredField("descriptor");
|
||||
field.setAccessible(true);
|
||||
|
||||
int fd = field.getInt(fileDescriptor);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 13) {
|
||||
return ParcelFileDescriptor.adoptFd(fd);
|
||||
} else {
|
||||
return ParcelFileDescriptor.dup(fileDescriptor);
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new IOException(e);
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new IOException(e);
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw new IOException(e);
|
||||
} catch (NoSuchFieldException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue