forked from Airblader/FeatureDetector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FeatureDetector.java
36 lines (27 loc) · 1.2 KB
/
FeatureDetector.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package org.apache.cordova.plugin;
import org.apache.cordova.api.CallbackContext;
import org.apache.cordova.api.CordovaPlugin;
import org.apache.cordova.api.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import android.util.Log;
public class FeatureDetector extends CordovaPlugin {
private static final String FEATURE_DETECTOR_TAG = "FeatureDetector";
private static final String ACTION_HAS_FEATURE = "hasFeature";
@Override
public boolean execute (String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
if (action.equals(ACTION_HAS_FEATURE)) {
String requestedFeature = args.getString(0);
hasFeature(requestedFeature, callbackContext);
return true;
} else {
Log.d(FEATURE_DETECTOR_TAG, "Invalid action");
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION, false));
return false;
}
}
private synchronized void hasFeature (String feature, CallbackContext callbackContext) {
boolean hasFeature = cordova.getActivity().getApplicationContext().getPackageManager().hasSystemFeature(feature);
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, hasFeature));
}
}