Skip to content
Open
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
44 changes: 16 additions & 28 deletions pickit/src/main/java/com/hbisoft/pickit/PickiT.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import android.content.Context;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.os.ParcelFileDescriptor;
import android.provider.DocumentsContract;
import android.util.Log;
Expand All @@ -15,8 +14,6 @@
import java.io.File;
import java.util.ArrayList;

import static com.hbisoft.pickit.Utils.getFilePath;

public class PickiT implements CallBackTask {
private final Context context;
private final PickiTCallbacks pickiTCallbacks;
Expand Down Expand Up @@ -75,42 +72,33 @@ public void getPath(Uri uri, int APILevel) {
}
// File was selected from Downloads provider
else if (docId !=null && docId.startsWith("msf")) {
String fileName = getFilePath(context, uri);
try {
File file = new File(Environment.getExternalStorageDirectory().toString() + "/Download/"+ fileName);
// If the file exists in the Downloads directory
// we can return the path directly
if (file.exists()){
pickiTCallbacks.PickiTonCompleteListener(file.getAbsolutePath(), false, false, true, "");
}
// The file is in a sub-directory in Downloads
// We will first try to make use of the /proc/ protocol
// if /proc/ doesn't work, or if there is any issue trying to get access to the file, it gets copied to the applications directory
else {
if (enableProc) {
ParcelFileDescriptor parcelFileDescriptor;
try {
parcelFileDescriptor = context.getContentResolver().openFileDescriptor(uri, "r");
int fd = parcelFileDescriptor.getFd();
int pid = android.os.Process.myPid();
String mediaFile = "/proc/" + pid + "/fd/" + fd;
File file1 = new File(mediaFile);
if (file1.exists() && file1.canRead() && file1.canWrite()) {
pickiTCallbacks.PickiTonCompleteListener(file1.getAbsolutePath(), false, false, true, "");
} else {
isMsfDownload = true;
downloadFile(uri);
}
} catch (Exception e) {
if (enableProc) {
ParcelFileDescriptor parcelFileDescriptor;
try {
parcelFileDescriptor = context.getContentResolver().openFileDescriptor(uri, "r");
int fd = parcelFileDescriptor.getFd();
int pid = android.os.Process.myPid();
String mediaFile = "/proc/" + pid + "/fd/" + fd;
File file1 = new File(mediaFile);
if (file1.exists() && file1.canRead() && file1.canWrite()) {
pickiTCallbacks.PickiTonCompleteListener(file1.getAbsolutePath(), false, false, true, "");
} else {
isMsfDownload = true;
downloadFile(uri);
}
} else {
} catch (Exception e) {
isMsfDownload = true;
downloadFile(uri);
}
} else {
isMsfDownload = true;
downloadFile(uri);
}
}catch (Exception e){
} catch (Exception e) {
isMsfDownload = true;
downloadFile(uri);
}
Expand Down