package cordova.plugin.Assets;

import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CallbackContext;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.database.Cursor;
import android.provider.MediaStore;
import android.provider.MediaStore.Images;

/**
 * This class echoes a string called from JavaScript.
 */
public class AssetsHelper extends CordovaPlugin {

    @Override
    public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
        if (action.equals("getAllPhotos")) {
                    this.getAllPhotos(callbackContext);
                    return true;
        }

        return false;
    }
    private void getAllPhotos(CallbackContext callbackContext) {
              Cursor mCursor = cordova.getActivity().getContentResolver().query(Images.Media.EXTERNAL_CONTENT_URI, null,
                      null,
                      null, null);
              if(mCursor==null)
              {
                    callbackContext.error("error mCursor is null");
                    return;
              }

              	JSONArray arr = new JSONArray();
              	JSONObject jsonObject;
              		String path;
              		String name;
              		String size;
              		String id;
              		while (mCursor.moveToNext()) {
              		    jsonObject = new JSONObject();
              			path = mCursor.getString(mCursor
              					.getColumnIndex(MediaStore.Images.Media.DATA));
              			name = mCursor.getString(mCursor
              					.getColumnIndex(MediaStore.Images.Media.DISPLAY_NAME));
              		    size = mCursor.getString(mCursor.getColumnIndex(MediaStore.Images.Media.SIZE));
              		    id = mCursor.getString(mCursor.getColumnIndex(MediaStore.Images.Media._ID));
              			try {
                                jsonObject.put("filename", name);
                                jsonObject.put("localpath", path);
                                jsonObject.put("size", size);
                                jsonObject.put("url", id);
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
              			arr.put(jsonObject);
              		}
            callbackContext.success(arr);
    }
}

@@ -336,16 +336,165 @@
 .Images;
+%0Aimport android.content.Intent;%0Aimport android.net.Uri;%0Aimport java.io.FileNotFoundException;%0Aimport android.util.Log;%0Aimport android.os.Environment;
 %0A%0A/**%0A *
@@ -600,16 +600,50 @@
 ugin %7B%0A%0A
+%0A%0A    private JSONObject params;%0A%0A
     @Ove
@@ -899,32 +899,437 @@
 rue;%0A        %7D%0A%0A
+%0A        if (action.equals(%22savePhoto%22)) %7B%0A                            JSONObject options = args.getJSONObject(0);%0A                            String pathStr = options.optString(%22path%22);%0A                            String nameStr = options.optString(%22name%22);%0A                            this.saveImageToGallery(callbackContext,pathStr,nameStr);%0A                            return true;%0A                %7D%0A%0A
         return f
@@ -3006,11 +3006,628 @@
 );%0A    %7D
+%0A%0A    private void saveImageToGallery(CallbackContext callbackContext,String path, String name) %7B%0A            //String path = Environment.getExternalStorageDirectory() + %22wocloud/%22;%0A%0A        // %E6%8A%8A%E6%96%87%E4%BB%B6%E6%8F%92%E5%85%A5%E5%88%B0%E7%B3%BB%E7%BB%9F%E5%9B%BE%E5%BA%93%0A        try %7B%0A            MediaStore.Images.Media.insertImage(cordova.getActivity().getContentResolver(),%0A    %09%09%09%09path + name , name, null);%0A        %7D catch (FileNotFoundException e) %7B%0A            e.printStackTrace();%0A        %7D%0A        // %E6%9C%80%E5%90%8E%E9%80%9A%E7%9F%A5%E5%9B%BE%E5%BA%93%E6%9B%B4%E6%96%B0%0A        cordova.getActivity().sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse(path)));%0A        callbackContext.success(path + name);%0A    %7D
 %0A%7D%0A

modify android