mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-19 07:02:51 +08:00
Refactoring based on feedback from Andrew
This commit is contained in:
parent
07912fdecd
commit
a0747aa960
@ -493,8 +493,7 @@ public class CordovaActivity extends Activity {
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, String permissions[],
|
||||
int[] grantResults) {
|
||||
PluginManager pm = this.appView.getPluginManager();
|
||||
pm.onRequestPermissionResult(requestCode, permissions, grantResults);
|
||||
cordovaInterface.onRequestPermissionResult(requestCode, permissions, grantResults);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -70,5 +70,6 @@ public interface CordovaInterface {
|
||||
*/
|
||||
public ExecutorService getThreadPool();
|
||||
|
||||
public void requestPermission(CordovaPlugin plugin);
|
||||
public void requestPermission(CordovaPlugin plugin, String permission);
|
||||
public void requestPermissions(CordovaPlugin plugin);
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ public class CordovaInterfaceImpl implements CordovaInterface {
|
||||
|
||||
protected ActivityResultHolder savedResult;
|
||||
protected CordovaPlugin activityResultCallback;
|
||||
protected CordovaPlugin permissionResultCallback;
|
||||
protected String initCallbackService;
|
||||
protected int activityResultRequestCode;
|
||||
|
||||
@ -162,9 +163,36 @@ public class CordovaInterfaceImpl implements CordovaInterface {
|
||||
}
|
||||
}
|
||||
|
||||
public void requestPermission(CordovaPlugin plugin)
|
||||
/**
|
||||
* Called by the system when the user grants permissions
|
||||
*
|
||||
* @param requestCode
|
||||
* @param permissions
|
||||
* @param grantResults
|
||||
*/
|
||||
public void onRequestPermissionResult(int requestCode, String[] permissions,
|
||||
int[] grantResults) {
|
||||
if(permissionResultCallback != null)
|
||||
{
|
||||
permissionResultCallback.onRequestPermissionResult(requestCode, permissions, grantResults);
|
||||
permissionResultCallback = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void requestPermission(CordovaPlugin plugin, String permission) {
|
||||
permissionResultCallback = plugin;
|
||||
String[] permissions = new String [1];
|
||||
permissions[0] = permission;
|
||||
int requestCode = 1;
|
||||
getActivity().requestPermissions(permissions, requestCode);
|
||||
}
|
||||
|
||||
public void requestPermissions(CordovaPlugin plugin)
|
||||
{
|
||||
pluginManager.requestPermission(plugin);
|
||||
permissionResultCallback = plugin;
|
||||
String[] permissions = plugin.getPermissionRequest();
|
||||
int requestCode = 1;
|
||||
getActivity().requestPermissions(permissions, requestCode);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -372,13 +372,6 @@ public class CordovaPlugin {
|
||||
return permissions;
|
||||
}
|
||||
|
||||
/**
|
||||
* requestPermission
|
||||
*/
|
||||
public void requestPermission() {
|
||||
cordova.requestPermission(this);
|
||||
}
|
||||
|
||||
public boolean hasPermisssion() {
|
||||
for(String p : permissions)
|
||||
{
|
||||
|
@ -511,26 +511,4 @@ public class PluginManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the system when the user grants permissions
|
||||
*
|
||||
* @param requestCode
|
||||
* @param permissions
|
||||
* @param grantResults
|
||||
*/
|
||||
public void onRequestPermissionResult(int requestCode, String[] permissions,
|
||||
int[] grantResults) {
|
||||
if(permissionRequester != null)
|
||||
{
|
||||
permissionRequester.onRequestPermissionResult(requestCode, permissions, grantResults);
|
||||
permissionRequester = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void requestPermission(CordovaPlugin plugin) {
|
||||
permissionRequester = plugin;
|
||||
String[] permissions = plugin.getPermissionRequest();
|
||||
int requestCode = 1;
|
||||
ctx.getActivity().requestPermissions(permissions, requestCode);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user