문제

i create a app for android with phonegap 3.0 and i want to check if the device has a flash ligth but i have problems with the method of getPackageManager() medthod,

here is the part of the java file, i get no errors by compiling on the device but the plugin does not work:

    ...
    import android.content.Context;
    import android.content.pm.PackageManager;

    public class Torch extends CordovaPlugin {


      Camera camera;
      Camera.Parameters Parameters;
      boolean hasFlash;
      Context my_service;

    /*  Constructor */
        public Torch() {  }

        public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {

            if (action.equals("shine")) {
                    hasFlash = my_service.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
                    if (!hasFlash) {  callbackContext.error("no torch found");  } 
                    else { this.shine(args.getBoolean(0));

        } ...

i tried also the code in eclipse, there it works only without the Context my_service instance.

hasFlash = getApplicationContext().getPackageManager()
                .hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);

        if (!hasFlash) { ...
도움이 되었습니까?

해결책

Try this

    boolean hasFlash = this.cordova.getActivity().getPackageManager()
                .hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top