package com.vaenow.appupdate.android;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONArray;
import org.json.JSONException;

/**
 * Created by LuoWen on 2015/10/27.
 */
public class CheckAppUpdate extends CordovaPlugin {
    public static final String TAG = "CheckAppUpdate";

    private UpdateManager updateManager = null;

    @Override
    public boolean execute(String action, JSONArray args, CallbackContext callbackContext)
            throws JSONException {

        if (action.equals("checkAppUpdate")) {
            getUpdateManager(args, callbackContext).checkUpdate();
            return true;
        }
        callbackContext.error(Utils.makeJSON(Constants.NO_SUCH_METHOD, "no such method: " + action));
        return false;
    }

    public UpdateManager getUpdateManager(JSONArray args, CallbackContext callbackContext)
            throws JSONException {

        if (this.updateManager == null) {
            this.updateManager = new UpdateManager(this.cordova.getActivity(), this.cordova);
        }

        return this.updateManager.options(args, callbackContext);
    }
}

@@ -32,16 +32,159 @@
 droid;%0A%0A
+import android.app.Activity;%0Aimport android.content.pm.PackageManager;%0Aimport android.Manifest;%0Aimport android.support.v4.app.ActivityCompat;%0A%0A
 import o
@@ -218,16 +218,16 @@
 ontext;%0A
-
 import o
@@ -519,16 +519,260 @@
  null;%0A%0A
+    // Storage Permissions%0A    private static final int REQUEST_EXTERNAL_STORAGE = 1;%0A    private static String%5B%5D PERMISSIONS_STORAGE = %7B%0A        Manifest.permission.READ_EXTERNAL_STORAGE,%0A        Manifest.permission.WRITE_EXTERNAL_STORAGE %7D;%0A%0A
     @Ove
@@ -947,24 +947,90 @@
 Update%22)) %7B%0A
+            verifyStoragePermissions(this.cordova.getActivity());%0A
             
@@ -1520,24 +1520,24 @@
 %0A        %7D%0A%0A
-
         retu
@@ -1595,11 +1595,504 @@
 );%0A    %7D
+%0A%0A    public static void verifyStoragePermissions(Activity activity) %7B%0A        // Check if we have write permission%0A        int permission = ActivityCompat.checkSelfPermission(activity,%0A        Manifest.permission.WRITE_EXTERNAL_STORAGE);%0A%0A        if (permission != PackageManager.PERMISSION_GRANTED) %7B%0A            // We don't have permission so prompt the user%0A            ActivityCompat.requestPermissions(activity, PERMISSIONS_STORAGE,%0A            REQUEST_EXTERNAL_STORAGE);%0A        %7D%0A    %7D
 %0A%7D%0A

Handle android EXTERNAL_STORAGE permissions in M