11
11
import android .provider .DocumentsContract ;
12
12
import android .provider .MediaStore ;
13
13
import android .webkit .MimeTypeMap ;
14
+ import android .util .Log ;
14
15
15
16
import androidx .annotation .Nullable ;
16
17
import androidx .documentfile .provider .DocumentFile ;
34
35
import java .util .concurrent .Executors ;
35
36
36
37
public class FileHelper {
38
+ static final String TAG = "FileHelper" ;
37
39
private Uri uri ;
38
40
private final ExecutorService executor = Executors .newSingleThreadExecutor ();
39
41
private final Handler handler ;
@@ -566,7 +568,11 @@ private void writeSyncInternal(Context context, byte[] content, boolean append)
566
568
os .write (content , 0 , content .length );
567
569
os .flush ();
568
570
os .close ();
569
- updateInternal (context );
571
+ try {
572
+ updateInternal (context );
573
+ } catch (Exception exception ){
574
+ Log .e (TAG , "Failed to updateValue: " + exception .getMessage ());
575
+ }
570
576
}
571
577
572
578
private void writeBufferSyncInternal (Context context , ByteBuffer content ) throws Exception {
@@ -579,7 +585,11 @@ private void writeBufferSyncInternal(Context context, ByteBuffer content, boolea
579
585
channel .write (content );
580
586
os .flush ();
581
587
os .close ();
582
- updateInternal (context );
588
+ try {
589
+ updateInternal (context );
590
+ } catch (Exception exception ){
591
+ Log .e (TAG , "Failed to updateValue: " + exception .getMessage ());
592
+ }
583
593
}
584
594
585
595
public void writeSync (Context context , byte [] content , @ Nullable Callback callback ) {
@@ -638,7 +648,11 @@ private void writeTextSyncInternal(Context context, String content, @Nullable St
638
648
osw .write (content );
639
649
osw .flush ();
640
650
osw .close ();
641
- updateInternal (context );
651
+ try {
652
+ updateInternal (context );
653
+ } catch (Exception exception ){
654
+ Log .e (TAG , "Failed to updateValue: " + exception .getMessage ());
655
+ }
642
656
}
643
657
644
658
public void writeTextSync (Context context , String content , @ Nullable String encoding , @ Nullable Callback callback ) {
@@ -764,14 +778,17 @@ private void renameInternal(Context context, String newName) throws Exception {
764
778
}
765
779
766
780
}
767
-
768
- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .R ) {
769
- context .getContentResolver ().update (uri , values , null );
770
- } else {
771
- context .getContentResolver ().update (uri , values , null , null );
781
+ try {
782
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .R ) {
783
+ context .getContentResolver ().update (uri , values , null );
784
+ } else {
785
+ context .getContentResolver ().update (uri , values , null , null );
786
+ }
787
+ updateInternal (context , false );
788
+ } catch (Exception exception ){
789
+ Log .e (TAG , "Failed to updateValue: " + exception .getMessage ());
772
790
}
773
-
774
- updateInternal (context , false );
791
+
775
792
}
776
793
777
794
public void renameSync (Context context , String newName , @ Nullable Callback callback ) {
0 commit comments