如何检查android cordova的设备功能?任何人都可以提供代码吗?上下文变量的错误..shows上下文变量在此位置为null,同时尝试在设备中运行显示强制关闭的代码!我正在尝试检查相机功能..请帮助...提前感谢
package com.troubling.android;
import org.apache.cordova.api.CallbackContext;
import org.apache.cordova.api.CordovaPlugin;
import org.json.JSONArray;
import org.json.JSONException;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.content.Context;
import android.util.Log;
public class Echo extends CordovaPlugin {
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws
JSONException
{
Context context = null;
PackageManager pm = this.cordova.getActivity().getPackageManager();
if (pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
Log.i("camera", "This device has camera!");
}
else{
Log.i("camera", "This device has no camera!");
}
return false;
}
private void echo(String message, CallbackContext callbackContext) {
if (message != null && message.length() > 0) {
callbackContext.success(message);
} else {
callbackContext.error("Expected one non-empty string argument.");
}
}
}
答案 0 :(得分:0)
试
PackageManager pm = this.cordova.getActivity().getApplicationContext().getPackageManager();