我用 phonegap 3.0 为 android 创建了一个应用程序,我想检查设备是否有闪光灯,但我对 getPackageManager() 方法有问题,
这是 java 文件的一部分,我在设备上编译没有错误,但插件不起作用:
...
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));
} ...
我也尝试了 eclipse 中的代码,只有在没有 Context my_service
实例的情况下它才能工作。
hasFlash = getApplicationContext().getPackageManager()
.hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
if (!hasFlash) { ...
最佳答案
试试这个
boolean hasFlash = this.cordova.getActivity().getPackageManager()
.hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
关于android - phonegap android 检查设备是否有闪存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19222213/