cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bows...@apache.org
Subject [1/3] cordova-plugin-media git commit: Refactored after feedback
Date Wed, 28 Oct 2015 19:01:51 GMT
Repository: cordova-plugin-media
Updated Branches:
  refs/heads/master bba9a7e30 -> 8dd328d71


Refactored after feedback


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/commit/8dd328d7
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/tree/8dd328d7
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/diff/8dd328d7

Branch: refs/heads/master
Commit: 8dd328d719df93e57c46727f4fe6cd753de2045c
Parents: c4547c9
Author: Joe Bowser <bowserj@apache.org>
Authored: Wed Sep 30 12:44:40 2015 -0700
Committer: Joe Bowser <bowserj@apache.org>
Committed: Wed Oct 28 12:01:42 2015 -0700

----------------------------------------------------------------------
 src/android/AudioHandler.java | 40 +++++++++++---------------------------
 1 file changed, 11 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/blob/8dd328d7/src/android/AudioHandler.java
----------------------------------------------------------------------
diff --git a/src/android/AudioHandler.java b/src/android/AudioHandler.java
index 49031c6..d5eb65f 100644
--- a/src/android/AudioHandler.java
+++ b/src/android/AudioHandler.java
@@ -60,6 +60,10 @@ public class AudioHandler extends CordovaPlugin {
     private CallbackContext messageChannel;
 
 
+    public static String [] permissions = { Manifest.permission.RECORD_AUDIO, Manifest.permission.WRITE_EXTERNAL_STORAGE};
+    public static int RECORD_AUDIO = 0;
+    public static int WRITE_EXTERNAL_STORAGE = 1;
+
     public static final int PERMISSION_DENIED_ERROR = 20;
 
     private String recordId;
@@ -73,38 +77,16 @@ public class AudioHandler extends CordovaPlugin {
         this.pausedForPhone = new ArrayList<AudioPlayer>();
     }
 
-    protected int checkWritePermission()
-    {
-        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
-        {
-            return cordova.getActivity().checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
-        }
-        else
-        {
-            return PackageManager.PERMISSION_GRANTED;
-        }
-    }
 
     protected void getWritePermission(int requestCode)
     {
-        cordova.requestPermission(this, requestCode, Manifest.permission.WRITE_EXTERNAL_STORAGE);
+        cordova.requestPermission(this, requestCode, permissions[WRITE_EXTERNAL_STORAGE]);
     }
 
-    protected int checkMicrophone()
-    {
-        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
-        {
-            return cordova.getActivity().checkSelfPermission(Manifest.permission.RECORD_AUDIO);
-        }
-        else
-        {
-            return PackageManager.PERMISSION_GRANTED;
-        }
-    }
 
     protected void getMicPermission(int requestCode)
     {
-        cordova.requestPermission(this, requestCode, Manifest.permission.RECORD_AUDIO);
+        cordova.requestPermission(this, requestCode, permissions[RECORD_AUDIO]);
     }
 
 
@@ -475,17 +457,17 @@ public class AudioHandler extends CordovaPlugin {
 
     private void promptForRecord()
     {
-        if(checkWritePermission() == PackageManager.PERMISSION_GRANTED  &&
-                checkMicrophone() == PackageManager.PERMISSION_GRANTED) {
+        if(cordova.hasPermission(permissions[WRITE_EXTERNAL_STORAGE])  &&
+                cordova.hasPermission(permissions[RECORD_AUDIO])) {
             this.startRecordingAudio(recordId, FileHelper.stripFileProtocol(fileUriStr));
         }
-        else if(checkMicrophone() == PackageManager.PERMISSION_GRANTED)
+        else if(cordova.hasPermission(permissions[RECORD_AUDIO]))
         {
-            getWritePermission(0);
+            getWritePermission(WRITE_EXTERNAL_STORAGE);
         }
         else
         {
-            getMicPermission(0);
+            getMicPermission(RECORD_AUDIO);
         }
 
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message