Skip to content

Commit

Permalink
Android webview Start时使用权限缓存,不要调起权限请求 xiangyuecn#46
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangyuecn committed Sep 5, 2019
1 parent b2c8ab5 commit f7c5058
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Binary file modified app-support-sample/demo_android/app-debug.apk.zip
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ static public class RecordApis {
static private final String LogTag="RecordApis";

static public void Async_recordPermission(final Request req) {
checkPermission(req, new Callback<Object, Object>() {
checkPermission(false, req, new Callback<Object, Object>() {
public Object Call(Object result, Exception hasError) {
if(result!=null){
req.callback(1, null);
Expand All @@ -344,10 +344,16 @@ public Object Call(Object result, Exception hasError) {
}
});
}
static private void checkPermission(final Request req, final Callback<Object, Object> callback){
static private boolean hasPermission;//如果检测到已授权,就不要再继续检测了,Activity.requestPermissions调用会导致webview长按录音时无法触发touchend事件 https://github.com/xiangyuecn/Recorder/issues/46
static private void checkPermission(boolean useCache, final Request req, final Callback<Object, Object> callback){
if(useCache && hasPermission){
callback.Call("ok", null);
return;
}
req.jsBridge.usesPermission.Request(new String[]{"android.permission.RECORD_AUDIO"}, new Runnable() {
@Override
public void run() {
hasPermission=true;
callback.Call("ok", null);
}
}, new Runnable() {
Expand All @@ -372,7 +378,7 @@ static public void Sync_recordAlive(Request req){
static public void Async_recordStart(final Request req){
DestroyCurrent();

checkPermission(req, new Callback<Object, Object>() {
checkPermission(true, req, new Callback<Object, Object>() {
public Object Call(Object result, Exception hasError) {
if(result==null){
req.callback(null, "没有录音权限");
Expand Down

0 comments on commit f7c5058

Please sign in to comment.