11package com .netease .im ;
22
3+ import android .content .Intent ;
4+ import android .net .Uri ;
5+ import android .provider .MediaStore ;
6+
37import com .facebook .react .bridge .Promise ;
48import com .facebook .react .bridge .ReactApplicationContext ;
9+ import com .facebook .react .bridge .ReactContext ;
510import com .facebook .react .bridge .ReactContextBaseJavaModule ;
611import com .facebook .react .bridge .ReactMethod ;
712
13+ import java .io .File ;
14+ import java .io .FileNotFoundException ;
15+
816/**
917 * Created by dowin on 2017/7/13.
1018 */
@@ -14,8 +22,10 @@ public class RNAppCacheUtilModule extends ReactContextBaseJavaModule {
1422 private final static String TAG = "AppCacheUtil" ;//AppCacheUtil.getCacheSize clearCache
1523 private final static String NAME = "AppCacheUtil" ;
1624
25+ private ReactContext reactContext ;
1726 public RNAppCacheUtilModule (ReactApplicationContext reactContext ) {
1827 super (reactContext );
28+ this .reactContext = reactContext ;
1929 }
2030
2131 @ Override
@@ -43,4 +53,20 @@ public void onCleanCache(boolean succeeded) {
4353 }
4454 });
4555 }
56+ @ ReactMethod
57+ public void saveImageToAlbum (String filePath , final Promise promise ) {
58+
59+ File imageFile = new File (filePath );
60+ if (imageFile .exists ()){
61+ try {
62+ MediaStore .Images .Media .insertImage (reactContext .getContentResolver (), imageFile .getAbsolutePath (), "title" , "description" );
63+ reactContext .sendBroadcast (new Intent (Intent .ACTION_MEDIA_SCANNER_SCAN_FILE , Uri .parse ("file://" + imageFile .getAbsolutePath ())));
64+ } catch (FileNotFoundException e ) {
65+ e .printStackTrace ();
66+ }
67+
68+ }
69+
70+
71+ }
4672}
0 commit comments