Skip to content
Permalink
Browse files
CB-10691: Check the context to avoid null errors
  • Loading branch information
infil00p committed Mar 1, 2016
1 parent d56ab5b commit 7c57ae9c0470905124c0d5a1430bf09f3a46f1cc
Showing 1 changed file with 14 additions and 10 deletions.
@@ -21,6 +21,7 @@ Licensed to the Apache Software Foundation (ASF) under one
import android.content.pm.PackageManager;
import android.Manifest;
import android.os.Build;
import android.util.Log;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaArgs;
@@ -41,6 +42,7 @@ public class Geolocation extends CordovaPlugin {


public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
Log.d(TAG, "We are entering execute");
context = callbackContext;
if(action.equals("getPermission"))
{
@@ -63,18 +65,20 @@ public void onRequestPermissionResult(int requestCode, String[] permissions,
int[] grantResults) throws JSONException
{
PluginResult result;
for(int r:grantResults)
{
if(r == PackageManager.PERMISSION_DENIED)
{
LOG.d(TAG, "Permission Denied!");
result = new PluginResult(PluginResult.Status.ILLEGAL_ACCESS_EXCEPTION);
context.sendPluginResult(result);
return;
//This is important if we're using Cordova without using Cordova, but we have the geolocation plugin installed
if(context != null) {
for (int r : grantResults) {
if (r == PackageManager.PERMISSION_DENIED) {
LOG.d(TAG, "Permission Denied!");
result = new PluginResult(PluginResult.Status.ILLEGAL_ACCESS_EXCEPTION);
context.sendPluginResult(result);
return;
}

}
result = new PluginResult(PluginResult.Status.OK);
context.sendPluginResult(result);
}
result = new PluginResult(PluginResult.Status.OK);
context.sendPluginResult(result);
}

public boolean hasPermisssion() {

0 comments on commit 7c57ae9

Please sign in to comment.