I am developing a Cordova plugin for Android, and it is difficult for me to overcome access to project resources due to the action - the plugin must be independent of the project, but access to resources (for example, R.java) is difficult.
My plugin, at the moment, consists of two very simple classes: RedLaser.javaand RedLaserScanner.java.
RedLaser.java
Inherits from CordovaPlugin and therefore contains a method executeand looks something like this:
public class RedLaser extends CordovaPlugin {
private static final string SCAN_ACTION = "scan";
public boolean execute(String action, final JSONArray args, final CallbackContext callbackContext) throws JSONException {
if (action.equals(SCAN_ACTION)) {
this.cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
scan(args, callbackContext);
}
});
return true;
}
return false;
}
private void scan(JSONArray args, CallbackContext callbackContext) {
Intent intent = new Intent(this.cordova.getActivity().getApplicationContext(), RedLaserScanner.class);
this.cordova.startActivityForResult((CordovaPlugin) this, intent, 1);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
}
}
RedLaserScanner.java
RedLaserScanner contains the Android activity logic and inherits from BarcodeScanActivity (which is the RedLaser SDK class, presumably itself inherits from Activity);
A very simple structure is as follows:
public class RedLaserScanner extends BarcodeScanActivity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.preview_overlay_new_portrait);
}
}
, R.layout.preview_overlay_new_portrait ( Eclipse), , com.myProject.myApp.R, .
cordova.getActivity().getResources(), , RedLaserScanner - CordovaPlugin.
-, , ?