Correct way to implement callback in plugin


#1

I’m trying to add a callback to a plugin that allows my app to play VR videos. In the plugin, there’s a GoogleVRPlayer.java file and a VrVideoActivity.java file.

Here’s what I have so far:

GoogleVRPlayer.java:

public class GoogleVRPlayer extends CordovaPlugin {
  public CallbackContext callback = null;
...
  public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException {
    if(action.equals("playVideo")) {
      String videoUrl = args.getString(0);
      Context context=this.cordova.getActivity().getApplicationContext();
      Intent intent=new Intent(context, VrVideoActivity.class);     
      intent.putExtra("videoUrl", videoUrl);
      intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      context.startActivity(intent);


      callback = callbackContext;

    }
    return true;
  }

}

In VrVideoActivity.java:

  @Override
    public void onLoadError(String errorMessage) {
      // An error here is normally due to being unable to decode the video format.
        callback.error(); // --> doesn't work
        this.callback.error(); // --> doesn't work either
        Log.e(TAG, "Error loading video: " + errorMessage);
    }

I’m getting this error:

error: cannot find symbol callback.error(); ^ symbol: variable callback

Any suggestions? I’m new to editing Cordova plugins…