You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by bo...@apache.org on 2015/10/28 20:01:51 UTC
[1/3] cordova-plugin-media git commit: Refactored after feedback
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 <bo...@apache.org>
Authored: Wed Sep 30 12:44:40 2015 -0700
Committer: Joe Bowser <bo...@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
[2/3] cordova-plugin-media git commit: Adding the media permissions
code
Posted by bo...@apache.org.
Adding the media permissions code
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/c4547c94
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/tree/c4547c94
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/diff/c4547c94
Branch: refs/heads/master
Commit: c4547c94c5850c619b0936551ec1180f4465a95b
Parents: ec1e9ba
Author: Joe Bowser <bo...@apache.org>
Authored: Thu Sep 24 15:46:24 2015 -0700
Committer: Joe Bowser <bo...@apache.org>
Committed: Wed Oct 28 12:01:42 2015 -0700
----------------------------------------------------------------------
src/android/AudioHandler.java | 88 +++++++++++++++++++++++++++++++++++++-
1 file changed, 86 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/blob/c4547c94/src/android/AudioHandler.java
----------------------------------------------------------------------
diff --git a/src/android/AudioHandler.java b/src/android/AudioHandler.java
index f06b75a..49031c6 100644
--- a/src/android/AudioHandler.java
+++ b/src/android/AudioHandler.java
@@ -22,11 +22,15 @@ import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaResourceApi;
+import android.Manifest;
import android.content.Context;
+import android.content.pm.PackageManager;
import android.media.AudioManager;
import android.net.Uri;
+import android.os.Build;
import android.util.Log;
+import java.security.Permission;
import java.util.ArrayList;
import org.apache.cordova.PluginResult;
@@ -55,6 +59,12 @@ public class AudioHandler extends CordovaPlugin {
private int origVolumeStream = -1;
private CallbackContext messageChannel;
+
+ public static final int PERMISSION_DENIED_ERROR = 20;
+
+ private String recordId;
+ private String fileUriStr;
+
/**
* Constructor.
*/
@@ -63,6 +73,41 @@ 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);
+ }
+
+ 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);
+ }
+
+
/**
* Executes the request and returns PluginResult.
* @param action The action to execute.
@@ -73,18 +118,19 @@ public class AudioHandler extends CordovaPlugin {
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
CordovaResourceApi resourceApi = webView.getResourceApi();
PluginResult.Status status = PluginResult.Status.OK;
+ messageChannel = callbackContext;
String result = "";
if (action.equals("startRecordingAudio")) {
+ recordId = args.getString(0);
String target = args.getString(1);
- String fileUriStr;
try {
Uri targetUri = resourceApi.remapUri(Uri.parse(target));
fileUriStr = targetUri.toString();
} catch (IllegalArgumentException e) {
fileUriStr = target;
}
- this.startRecordingAudio(args.getString(0), FileHelper.stripFileProtocol(fileUriStr));
+ promptForRecord();
}
else if (action.equals("stopRecordingAudio")) {
this.stopRecordingAudio(args.getString(0));
@@ -407,4 +453,42 @@ public class AudioHandler extends CordovaPlugin {
messageChannel.sendPluginResult(pluginResult);
}
}
+
+ public void onRequestPermissionResult(int requestCode, String[] permissions,
+ int[] grantResults) throws JSONException
+ {
+ for(int r:grantResults)
+ {
+ if(r == PackageManager.PERMISSION_DENIED)
+ {
+ this.messageChannel.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, PERMISSION_DENIED_ERROR));
+ return;
+ }
+ }
+ promptForRecord();
+ }
+
+ /*
+ * This little utility method catch-all work great for multi-permission stuff.
+ *
+ */
+
+ private void promptForRecord()
+ {
+ if(checkWritePermission() == PackageManager.PERMISSION_GRANTED &&
+ checkMicrophone() == PackageManager.PERMISSION_GRANTED) {
+ this.startRecordingAudio(recordId, FileHelper.stripFileProtocol(fileUriStr));
+ }
+ else if(checkMicrophone() == PackageManager.PERMISSION_GRANTED)
+ {
+ getWritePermission(0);
+ }
+ else
+ {
+ getMicPermission(0);
+ }
+
+ }
+
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[3/3] cordova-plugin-media git commit: Adding engine tag
Posted by bo...@apache.org.
Adding engine tag
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/ec1e9ba6
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/tree/ec1e9ba6
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/diff/ec1e9ba6
Branch: refs/heads/master
Commit: ec1e9ba6422c6e596e710e220102b85ccf5546fb
Parents: bba9a7e
Author: Joe Bowser <bo...@apache.org>
Authored: Thu Sep 24 11:17:39 2015 -0700
Committer: Joe Bowser <bo...@apache.org>
Committed: Wed Oct 28 12:01:42 2015 -0700
----------------------------------------------------------------------
plugin.xml | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/blob/ec1e9ba6/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index 7e1f216..f3fc66d 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -29,7 +29,10 @@ id="cordova-plugin-media"
<keywords>cordova,media</keywords>
<repo>https://git-wip-us.apache.org/repos/asf/cordova-plugin-media.git</repo>
<issue>https://issues.apache.org/jira/browse/CB/component/12320647</issue>
-
+
+ <engines>
+ <engine name="cordova-android" version=">=5.0.0-dev" />
+ </engines>
<dependency id="cordova-plugin-file" version=">=2.0.0" />
<js-module src="www/MediaError.js" name="MediaError">
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org