From f89f001559d098a236463f7cb56de05b360ad0aa Mon Sep 17 00:00:00 2001 From: hss01248 Date: Tue, 9 Apr 2024 15:20:13 +0800 Subject: [PATCH] =?UTF-8?q?fix(bug):=20=E7=BB=BC=E5=90=88=E8=A7=A3?= =?UTF-8?q?=E5=86=B3=E6=9C=89=E6=97=A0=E5=9B=9E=E8=B0=83=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- activityresult/build.gradle | 6 +- .../GoOutOfAppForResultFragment.java | 87 ++++- .../activityresult/InAppResultFragment.java | 74 +++- app/build.gradle | 11 +- app/src/main/AndroidManifest.xml | 6 +- .../transfragmentdemo/FileDeleteUtil.java | 337 ++++++++++++++++++ .../transfragmentdemo/MainActivity.java | 51 +++ app/src/main/res/layout/activity_main.xml | 7 + build.gradle | 4 +- gradle/wrapper/gradle-wrapper.properties | 2 +- .../hss01248/transfrag/BaseTransFragment.java | 18 +- 11 files changed, 570 insertions(+), 33 deletions(-) create mode 100644 app/src/main/java/com/hss01248/transfragmentdemo/FileDeleteUtil.java diff --git a/activityresult/build.gradle b/activityresult/build.gradle index d420c32..f52476b 100644 --- a/activityresult/build.gradle +++ b/activityresult/build.gradle @@ -31,9 +31,9 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - api 'androidx.appcompat:appcompat:1.1.0' - api 'androidx.activity:activity:1.1.0' - api 'androidx.fragment:fragment:1.1.0' + api 'androidx.appcompat:appcompat:1.2.0' + api 'androidx.activity:activity:1.2.0' + api 'androidx.fragment:fragment:1.2.0' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' diff --git a/activityresult/src/main/java/com/hss01248/activityresult/GoOutOfAppForResultFragment.java b/activityresult/src/main/java/com/hss01248/activityresult/GoOutOfAppForResultFragment.java index cb46cb3..c30e1e1 100644 --- a/activityresult/src/main/java/com/hss01248/activityresult/GoOutOfAppForResultFragment.java +++ b/activityresult/src/main/java/com/hss01248/activityresult/GoOutOfAppForResultFragment.java @@ -1,11 +1,13 @@ package com.hss01248.activityresult; import android.content.Intent; +import android.os.Bundle; import android.os.Handler; import android.os.Looper; import android.util.Log; import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentActivity; import com.hss01248.transfrag.BaseTransFragment; @@ -31,22 +33,32 @@ * 2023-06-02 09:51:54.975 3295-3295/com.hss01248.transfragmentdemo D/frag: onDestroy:GoOutOfAppForResultFragment{993ff35} (579cc2d3-2ea6-4aea-93c0-e75343cdeccc tag=25328484-3fe6-4b3c-9061-9be1fbc79070) * 2023-06-02 09:51:55.025 3295-3295/com.hss01248.transfragmentdemo D/DecorView[]: onWindowFocusChanged hasWindowFocus true */ - public class GoOutOfAppForResultFragment extends BaseTransFragment { + public class GoOutOfAppForResultFragment extends Fragment { int requestCode; ActivityResultListener listener; boolean startWaitingResult; boolean consumed; + boolean firstOnResume2 = true; + + protected FragmentActivity activity; + protected Intent bean; + boolean firstResume = true; + public static boolean debugable = true; public GoOutOfAppForResultFragment() { super(); } public GoOutOfAppForResultFragment(FragmentActivity activity, Intent intent) { - super(activity, intent); + this(); + this.activity = activity; + this.bean = intent; + BaseTransFragment.startFragmentTransaction(activity,this); } public void goOutApp(ActivityResultListener listener){ + requestCode = new Random().nextInt(8799); this.listener = listener; if (StartActivityUtil.debugable) { @@ -56,9 +68,20 @@ public void goOutApp(ActivityResultListener listener){ if(!listener.onInterceptStartIntent(this,bean,requestCode)){ startActivityForResult(bean,requestCode); } + }catch (Throwable throwable){ listener.onActivityNotFound(throwable); - finish(); + BaseTransFragment.finish(this); + } + } + + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + firstOnResume2 = true; + setRetainInstance(true); + if(debugable){ + Log.d("frag","onCreate:"+this); } } @@ -66,25 +89,54 @@ public void goOutApp(ActivityResultListener listener){ public void onStop() { super.onStop(); startWaitingResult = true; + if(debugable){ + Log.d("frag","onStop:"+this); + } } - //todo 一些半屏activity,只触发fragment的onPause, 不触发onStop - /* @Override + long lastPause = 0; + @Override public void onPause() { super.onPause(); + if(debugable){ + Log.d("frag","onPause:"+this); + } + lastPause = System.currentTimeMillis(); + //对于打开通知权限这种,没有回调的,就会在onpause后立刻回调onActivityResult + //如何处理? --> 在onStop后开始响应onActivityResult startWaitingResult = true; } @Override public void onResume() { + if(debugable){ + Log.d("frag","onresume:"+this); + } super.onResume(); - if(startWaitingResult && !consumed){ - onStartOfResultBack(requestCode,66,null); - startWaitingResult = false; + + if(firstResume){ + onFirstResume(); + firstResume = false; + } + } + @Override + public void onDestroy() { + super.onDestroy(); + if(debugable){ + Log.d("frag","onDestroy:"+this); } - }*/ + BaseTransFragment.finish(this); + } + + + protected void onFirstResume() { + + } + //todo 一些半屏activity,只触发fragment的onPause, 不触发onStop, 比如删除图片的reqeust弹窗. + //todo onActivityResult比onResume先触发 + /** * 如果真有,那么比onStart()先执行 * @param requestCode @@ -94,6 +146,15 @@ public void onResume() { @Override public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); + if(debugable){ + Log.d("frag","onActivityResult0:"+this); + } + if(System.currentTimeMillis() - lastPause < 500){ + if (StartActivityUtil.debugable) { + Log.w("onActivityResult", "onActivityResult和onpause间隔太短,是无效的:" + requestCode + ",result:" + resultCode + ",data:" + data); + } + return; + } if(startWaitingResult){ consumed = true; if (StartActivityUtil.debugable) { @@ -113,7 +174,11 @@ public void onActivityResult(int requestCode, int resultCode, @Nullable Intent d public void onStart() { super.onStart(); if (StartActivityUtil.debugable) { - Log.i("frag", "on start frag req:" + requestCode + ","+this.toString() ); + Log.i("frag", "on start frag req:" + requestCode + ","+firstOnResume2+"-"+this.toString() ); + } + if(firstOnResume2){ + firstOnResume2 = false; + return; } //有时,onStart会在onActivityResult之前走,所以要等一会儿 new Handler(Looper.getMainLooper()).postDelayed(new Runnable() { @@ -144,7 +209,7 @@ protected void onStartOfResultBack(int requestCode, int resultCode, @Nullable In if (StartActivityUtil.debugable) { Log.i("onActivityResult2", "frag req:" + requestCode + ",result:onStartOfResultBack,data:"+data ); } - finish(); + BaseTransFragment.finish(this); } diff --git a/activityresult/src/main/java/com/hss01248/activityresult/InAppResultFragment.java b/activityresult/src/main/java/com/hss01248/activityresult/InAppResultFragment.java index 6ce37e2..93cccec 100644 --- a/activityresult/src/main/java/com/hss01248/activityresult/InAppResultFragment.java +++ b/activityresult/src/main/java/com/hss01248/activityresult/InAppResultFragment.java @@ -1,9 +1,11 @@ package com.hss01248.activityresult; import android.content.Intent; +import android.os.Bundle; import android.util.Log; import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentActivity; import com.hss01248.transfrag.BaseTransFragment; @@ -15,14 +17,22 @@ * author:hss * desription: */ - public class InAppResultFragment extends BaseTransFragment { + public class InAppResultFragment extends Fragment { + + protected FragmentActivity activity; + protected Intent bean; + boolean firstResume = true; + public static boolean debugable = true; public InAppResultFragment() { super(); } public InAppResultFragment(FragmentActivity activity, Intent intent) { - super(activity, intent); + this(); + this.activity = activity; + this.bean = intent; + BaseTransFragment.startFragmentTransaction(activity,this); } ActivityResultListener listener; int requestCode; @@ -51,7 +61,7 @@ public void onActivityResult(int requestCode, int resultCode, @Nullable Intent d if(listener != null){ listener.onActivityResult(requestCode,resultCode,data); } - finish(); + BaseTransFragment.finish(this); if(requestCode == this.requestCode){ //listener.onActivityResult(requestCode,resultCode,data); //finish(); @@ -60,7 +70,65 @@ public void onActivityResult(int requestCode, int resultCode, @Nullable Intent d Log.w("onActivityResult", "reqcode not same:" + requestCode + ",this.requestCode:" + this.requestCode ); } } + } + + + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setRetainInstance(true); + if(debugable){ + Log.d("frag","onCreate:"+this); + } + // firstResume = true; + } + + @Override + public void onStart() { + super.onStart(); + if(debugable){ + Log.d("frag","onStart:"+this); + } + } + + @Override + public void onResume() { + if(debugable){ + Log.d("frag","onresume:"+this); + } + super.onResume(); + if(firstResume){ + onFirstResume(); + firstResume = false; + } + } + + + protected void onFirstResume() { + } + + @Override + public void onPause() { + super.onPause(); + if(debugable){ + Log.d("frag","onPause:"+this); + } + } + @Override + public void onStop() { + super.onStop(); + if(debugable){ + Log.d("frag","onStop:"+this); + } + } + @Override + public void onDestroy() { + super.onDestroy(); + if(debugable){ + Log.d("frag","onDestroy:"+this); + } + BaseTransFragment.finish(this); } } diff --git a/app/build.gradle b/app/build.gradle index 5bb8e75..eadc0e3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,12 +1,12 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 29 - buildToolsVersion "29.0.1" + compileSdkVersion 33 + buildToolsVersion "30.0.3" defaultConfig { applicationId "com.hss01248.transfragmentdemo" - minSdkVersion 16 - targetSdkVersion 29 + minSdkVersion 24 + targetSdkVersion 33 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" @@ -37,7 +37,10 @@ dependencies { implementation project (':activityresult') implementation project (':transactivity') api 'com.blankj:utilcodex:1.30.6' + implementation "androidx.multidex:multidex:2.0.1" api 'com.github.hss01248.MyPermission:permission:2.2.9' + api('com.github.skyNet2017.Luban:dataForPhotoSelet:3.3.0') + api 'com.github.getActivity:XXPermissions:11.6' //api "com.github.hss01248.MyPermission:location:2.2.4" } configurations { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index de9f131..52e8205 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,6 +2,9 @@ + + + - + diff --git a/app/src/main/java/com/hss01248/transfragmentdemo/FileDeleteUtil.java b/app/src/main/java/com/hss01248/transfragmentdemo/FileDeleteUtil.java new file mode 100644 index 0000000..4e26d20 --- /dev/null +++ b/app/src/main/java/com/hss01248/transfragmentdemo/FileDeleteUtil.java @@ -0,0 +1,337 @@ +package com.hss01248.transfragmentdemo; + +import android.Manifest; +import android.app.Activity; +import android.app.PendingIntent; +import android.app.RecoverableSecurityException; +import android.content.ContentResolver; +import android.content.ContentUris; +import android.content.Intent; +import android.content.IntentSender; +import android.database.Cursor; +import android.net.Uri; +import android.os.Build; +import android.os.Environment; +import android.provider.MediaStore; +import android.provider.Settings; +import android.text.TextUtils; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; + +import com.blankj.utilcode.util.ActivityUtils; +import com.blankj.utilcode.util.LogUtils; +import com.blankj.utilcode.util.PermissionUtils; +import com.blankj.utilcode.util.Utils; +import com.hjq.permissions.OnPermissionCallback; +import com.hjq.permissions.Permission; +import com.hjq.permissions.XXPermissions; +import com.hss01248.activityresult.ActivityResultListener; +import com.hss01248.activityresult.StartActivityUtil; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import io.reactivex.Observer; + +/** + * @Despciption + * 在一次操作中修改或删除多个媒体文件 + * 根据应用在哪个 Android 版本上运行来纳入逻辑。 + * + * 在 Android 11 上运行 + * 请使用以下方法: + * + * 使用 MediaStore.createWriteRequest() 或 MediaStore.createTrashRequest() 为应用的写入或删除请求创建待定 intent,然后通过调用该 intent 提示用户授予修改一组文件的权限。 + * 评估用户的响应: + * + * 如果授予了权限,请继续修改或删除操作。 + * 如果未授予权限,请向用户说明您的应用中的功能为何需要该权限。 + * 详细了解如何使用 Android 11 及更高版本提供的这些方法管理媒体文件组。 + * + * 在 Android 10 上运行 + * 如果您的应用以 Android 10(API 级别 29)为目标平台,请停用分区存储,继续使用适用于 Android 9 及更低版本的方法来执行此操作。 + * + * 在 Android 9 或更低版本上运行 + * 请使用以下方法: + * + * 按照请求应用权限中所述的最佳做法,请求 WRITE_EXTERNAL_STORAGE 权限。 + * 使用 MediaStore API 修改或删除媒体文件。 + * + * + * https://blog.csdn.net/CHENEY0314/article/details/124216224 + * + * @Author hss + * @Date 23/02/2022 11:23 + * @Version 1.0 + */ +public class FileDeleteUtil { + + + + + // 注意compileSdkVersion和targetSdkVersion均需要 >= 31 + public static void checkMediaManagerPermission() { + // + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + boolean canManageMedia = MediaStore.canManageMedia(Utils.getApp()); + if(canManageMedia){ + LogUtils.i("已经有管理媒体的权限了"); + }else { + LogUtils.i("还没有管理媒体的权限,去申请"); + Intent intent = new Intent(Settings.ACTION_REQUEST_MANAGE_MEDIA); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + ActivityUtils.getTopActivity().startActivity(intent); + } + }else { + LogUtils.i("Android版本小于12,还不需要这个管理媒体的权限"); + } + } + + + public static void deleteImage(String path,boolean canHaveUI, Observer callBack) { + if(TextUtils.isEmpty(path)){ + callBack.onNext(true); + return; + } + File file = new File(path); + if(!file.exists()){ + LogUtils.d("file not exist",path); + callBack.onNext(true); + return; + } + if(Build.VERSION.SDK_INT < Build.VERSION_CODES.M){ + if(!file.canWrite()){ + LogUtils.w("Android6以下,系统自定义存储权限没有允许"); + } + boolean isSuccess = file.delete(); + if (isSuccess) { + callBack.onNext(true); + } else { + callBack.onNext(false); + } + return; + } + + if(!file.canWrite()){ + //申请权限的模块 + if(!canHaveUI){ + callBack.onError(new Exception("no permission")); + return; + } + askWritePermission(path, canHaveUI, callBack); + return; + } + //有权限时,Android10以下,还是直接使用File api: + if(Build.VERSION.SDK_INT < Build.VERSION_CODES.Q){ + // + boolean isSuccess = new File(path).delete(); + if (isSuccess) { + callBack.onNext(true); + } else { + callBack.onNext(false); + } + return; + } + //android10以上,通过media store来删除 + try { + List uris = new ArrayList<>(); + + //这个uri应该是从mediastore查出来的uri,而不是自己通过file构建的: + //uris.add(OpenUri.fromFile(Utils.getApp(),new File(path))); + ContentResolver resolver = Utils.getApp().getContentResolver(); // 通过context上下文可拿到 + + //区分: 图片/视频/音频 + Cursor cursor = MediaStore.Images.Media.query(resolver, + MediaStore.Images.Media.EXTERNAL_CONTENT_URI, + new String[]{MediaStore.Images.Media._ID}, + MediaStore.Images.Media.DATA + "=?", + new String[]{path}, null); + if (null != cursor && cursor.moveToFirst()) { + long id = cursor.getLong(0); + Uri contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; + Uri uri = ContentUris.withAppendedId(contentUri, id); + uris.add(uri); + } + + PendingIntent deleteRequest = null; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + deleteRequest = MediaStore.createDeleteRequest(Utils.getApp().getContentResolver(), uris); + // java.lang.IllegalArgumentException: All requested items must be referenced by specific ID + PendingIntent finalDeleteRequest = deleteRequest; + StartActivityUtil.goOutAppForResult(ActivityUtils.getTopActivity(), null, new ActivityResultListener() { + @Override + public boolean onInterceptStartIntent(@NonNull Fragment fragment, @Nullable Intent intent, int requestCode) { + try { + /* ActivityUtils.getTopActivity().startIntentSenderForResult( + exception.getUserAction().getActionIntent().getIntentSender(), + requestCode, + null, + 0, 0, 0, null);*/ + fragment.startIntentSenderForResult(finalDeleteRequest.getIntentSender(), + requestCode, null, 0, 0, 0, null); + } catch (IntentSender.SendIntentException e) { + LogUtils.w(e); + callBack.onError(e); + } + return true; + } + + @Override + public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { + //这里没有回调 + if(resultCode == Activity.RESULT_OK){ + callBack.onNext(true); + }else { + callBack.onNext(false); + } + } + + @Override + public void onActivityNotFound(Throwable e) { + LogUtils.w(e); + callBack.onError(e); + } + }); + return; + } + } catch (Exception e) { + LogUtils.w(path,e); + } + + + //原文链接:https://blog.csdn.net/zjuter/article/details/121670823 + + + //Android10及以上,使用MediaStore操作. + Cursor cursor = MediaStore.Images.Media.query( + Utils.getApp().getContentResolver(), + MediaStore.Images.Media.EXTERNAL_CONTENT_URI, + new String[]{MediaStore.Images.Media._ID}, + MediaStore.Images.Media.DATA.toString() + "=?", + new String[]{path}, + null); + + try { + if (cursor.moveToFirst()) { + Long id = cursor.getLong(0); + Uri contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; + Uri uri = ContentUris.withAppendedId(contentUri, id); + + int count = Utils.getApp().getContentResolver().delete(uri, null, null); + + //todo 在华为手机上依然被拦截 + + + if (count > 0) { + callBack.onNext(true); + } else { + callBack.onNext(false); + } + } else { + LogUtils.w("无法使用media store删除,还得用file.delete"); + boolean isSuccess = new File(path).delete(); + if (isSuccess) { + callBack.onNext(true); + } else { + callBack.onNext(false); + } + } + }catch (Throwable throwable){ + LogUtils.w(throwable); + if (canHaveUI && Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && throwable instanceof RecoverableSecurityException) { + RecoverableSecurityException exception = (RecoverableSecurityException) throwable; + + StartActivityUtil.goOutAppForResult(ActivityUtils.getTopActivity(), null, new ActivityResultListener() { + @Override + public boolean onInterceptStartIntent(@NonNull Fragment fragment, @Nullable Intent intent, int requestCode) { + try { + ActivityUtils.getTopActivity().startIntentSenderForResult( + exception.getUserAction().getActionIntent().getIntentSender(), + requestCode, + null, + 0, 0, 0, null); + } catch (IntentSender.SendIntentException e) { + LogUtils.w(e); + callBack.onError(e); + } + return true; + } + + @Override + public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { + if(resultCode == Activity.RESULT_OK){ + callBack.onNext(true); + }else { + callBack.onNext(false); + } + } + + @Override + public void onActivityNotFound(Throwable e) { + LogUtils.w(e); + callBack.onError(e); + } + }); + }else { + callBack.onError(throwable); + } + } + } + + private static void askWritePermission(String path, boolean canHaveUI, Observer callBack) { + if(Build.VERSION.SDK_INT < Build.VERSION_CODES.Q + || (Build.VERSION.SDK_INT == Build.VERSION_CODES.Q + && Environment.isExternalStorageLegacy())){ + //android10以下 + //或者Android10,兼容模式下 请求WRITE_EXTERNAL_STORAGE + PermissionUtils.permission(Manifest.permission.WRITE_EXTERNAL_STORAGE) + .callback(new PermissionUtils.SimpleCallback() { + @Override + public void onGranted() { + deleteImage(path, canHaveUI, callBack); + } + + @Override + public void onDenied() { + callBack.onError(new Exception("no permission")); + } + }).request(); + + }else { + //todo Android10,且为分区存储时(非兼容模式),权限怎么申请? + //请求manage权限 + XXPermissions.with(ActivityUtils.getTopActivity()) + .permission(Permission.MANAGE_EXTERNAL_STORAGE) + .request(new OnPermissionCallback() { + @Override + public void onGranted(List permissions, boolean all) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + if(Environment.isExternalStorageManager()){ + deleteImage(path, canHaveUI, callBack); + return; + } + } + callBack.onError(new Exception("no permission")); + } + + @Override + public void onDenied(List permissions, boolean never) { + OnPermissionCallback.super.onDenied(permissions, never); + callBack.onError(new Exception("no permission")); + } + }); + + + + //No Activity found to handle Intent + // Intent intent = new Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION); + // intent.setPackage(AppUtils.getAppPackageName()); + // StartActivityUtil.goOutAppForResult(ActivityUtils.getTopActivity(), intent, new ActivityResultListener() { + + + } + } +} diff --git a/app/src/main/java/com/hss01248/transfragmentdemo/MainActivity.java b/app/src/main/java/com/hss01248/transfragmentdemo/MainActivity.java index ba58b76..0c51fd4 100644 --- a/app/src/main/java/com/hss01248/transfragmentdemo/MainActivity.java +++ b/app/src/main/java/com/hss01248/transfragmentdemo/MainActivity.java @@ -25,15 +25,22 @@ import com.blankj.utilcode.util.ActivityUtils; import com.blankj.utilcode.util.LogUtils; import com.blankj.utilcode.util.PermissionUtils; +import com.blankj.utilcode.util.ToastUtils; import com.hss01248.activityresult.ActivityResultListener; import com.hss01248.activityresult.StartActivityUtil; import com.hss01248.activityresult.TheActivityListener; +import com.hss01248.image.dataforphotoselet.ImgDataSeletor; import com.hss01248.permission.MyPermissions; import com.hss01248.transactivity.DialogPriorityUtil; import com.hss01248.transactivity.TransActivity; +import org.devio.takephoto.wrap.TakeOnePhotoListener; + import java.util.List; +import io.reactivex.Observer; +import io.reactivex.disposables.Disposable; + public class MainActivity extends AppCompatActivity { @@ -303,4 +310,48 @@ public void onDenied(@NonNull List deniedForever, @NonNull List } }, Manifest.permission.READ_EXTERNAL_STORAGE); } + + public void halfDialog(View view) { + ImgDataSeletor.startPickOneWitchDialog(this, new TakeOnePhotoListener() { + @Override + public void onSuccess(String path) { + /* File file = new File(path); + boolean delete = file.delete(); + ToastUtils.showLong("是否删除成功:"+ delete);*/ + //即使是true,也会被小米系统拦截 + FileDeleteUtil.deleteImage(path,true, new Observer() { + @Override + public void onSubscribe(@io.reactivex.annotations.NonNull Disposable d) { + + } + + @Override + public void onNext(@io.reactivex.annotations.NonNull Boolean aBoolean) { + ToastUtils.showLong("是否删除成功:"+ aBoolean); + } + + @Override + public void onError(@io.reactivex.annotations.NonNull Throwable e) { + + } + + @Override + public void onComplete() { + + } + }); + + } + + @Override + public void onFail(String path, String msg) { + + } + + @Override + public void onCancel() { + + } + }); + } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index c7a88bd..b04aa6c 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -39,6 +39,11 @@ android:text="跳到系统通知权限界面-无回调" android:layout_width="match_parent" android:layout_height="wrap_content"/> +