Skip to content

Commit

Permalink
Add context when deleting temp folder + Android 11 bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
HBiSoft committed Jul 31, 2020
1 parent 2b49b48 commit 0773577
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 39 deletions.
13 changes: 10 additions & 3 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 28
compileSdkVersion 30
defaultConfig {
applicationId "com.hbisoft.pickitexample"
minSdkVersion 16
targetSdkVersion 28
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -20,10 +20,10 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation project(path: ':pickit')
}
4 changes: 2 additions & 2 deletions app/src/main/java/com/hbisoft/pickitexample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public void PickiTonCompleteListener(String path, boolean wasDriveFile, boolean
// Deleting the temporary file if it exists
@Override
public void onBackPressed() {
pickiT.deleteTemporaryFile();
pickiT.deleteTemporaryFile(this);
super.onBackPressed();
}

Expand All @@ -264,7 +264,7 @@ public void onBackPressed() {
public void onDestroy() {
super.onDestroy();
if (!isChangingConfigurations()) {
pickiT.deleteTemporaryFile();
pickiT.deleteTemporaryFile(this);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ protected String doInBackground(Uri... params) {
Context context = mContext.get();
if (context != null) {
folder = context.getExternalFilesDir("Temp");
if (folder!= null && !folder.exists()) {
if (folder.mkdirs()) {
Log.i("PickiT : ", "Temp folder createdd");
}
}
returnCursor = context.getContentResolver().query(mUri, null, null, null, null);
try {
is = context.getContentResolver().openInputStream(mUri);
Expand Down
12 changes: 9 additions & 3 deletions pickit/src/main/java/com/hbisoft/pickit/PickiT.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void getPath(Uri uri, int APILevel){
// Local file was selected
else {
returnedPath = Utils.getRealPathFromURI_API19(context, uri);
Log.e("RETURNED -", ""+returnedPath);

//Get the file extension
final MimeTypeMap mime = MimeTypeMap.getSingleton();
Expand Down Expand Up @@ -67,6 +68,11 @@ public void getPath(Uri uri, int APILevel){
//Copy the file to the temporary folder
downloadFile(uri);
return;
}else if (Utils.errorReason() != null && Utils.errorReason().equals("uri")){
isFromUnknownProvider = true;
//Copy the file to the temporary folder
downloadFile(uri);
return;
}
}
}
Expand All @@ -84,7 +90,7 @@ public void getPath(Uri uri, int APILevel){
// Remember if the extension can't be found, it will not be added, but you will still be able to use the file
//Todo: Add checks for unknown file extensions

if (!subStringExtension.equals(extensionFromMime) && uri.getScheme() != null && uri.getScheme().equals(ContentResolver.SCHEME_CONTENT)) {
if (!subStringExtension.equals("jpeg") && !subStringExtension.equals(extensionFromMime) && uri.getScheme() != null && uri.getScheme().equals(ContentResolver.SCHEME_CONTENT)) {
isFromUnknownProvider = true;
downloadFile(uri);
return;
Expand Down Expand Up @@ -112,7 +118,7 @@ private void downloadFile(Uri uri){
public void cancelTask(){
if (asyntask!=null){
asyntask.cancel(true);
deleteTemporaryFile();
deleteTemporaryFile(context);
}
}

Expand Down Expand Up @@ -166,7 +172,7 @@ public void PickiTonPostExecute(String path, boolean wasDriveFile, boolean wasSu
}

// Delete the temporary folder
public void deleteTemporaryFile(){
public void deleteTemporaryFile(Context context){
File folder = context.getExternalFilesDir("Temp");
if (folder != null) {
if (deleteDirectory(folder)){
Expand Down
26 changes: 0 additions & 26 deletions pickit/src/main/java/com/hbisoft/pickit/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,32 +165,6 @@ else if (sub4.equals("Download")){
}
}

@SuppressLint("SdCardPath")
@SuppressWarnings("SpellCheckingInspection")
private static String[] KNOWN_SD_PATHS = new String[]{
"/storage/sdcard0",
"/storage/sdcard1",
"/storage/extsdcard",
"/storage/sdcard0/external_sdcard",
"/mnt/extsdcard",
"/mnt/sdcard/external_sd",
"/mnt/sdcard/ext_sd",
"/mnt/external_sd",
"/mnt/media_rw/sdcard1",
"/removable/microsd",
"/mnt/emmc",
"/storage/external_SD",
"/storage/ext_sd",
"/storage/removable/sdcard1",
"/data/sdext",
"/data/sdext2",
"/data/sdext3",
"/data/sdext4",
"/sdcard1",
"/sdcard2",
"/storage/microsd"
};

static String getRealPathFromURI_BelowAPI19(Context context, Uri contentUri) {
String[] proj = {MediaStore.Video.Media.DATA};
CursorLoader loader = new CursorLoader(context, contentUri, proj, null, null, null);
Expand Down

0 comments on commit 0773577

Please sign in to comment.