mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-22 08:53:24 +08:00
Port Device to use CordovaPlugin.
This commit is contained in:
parent
d72a8cbf89
commit
dd8533a320
@ -20,9 +20,10 @@ package org.apache.cordova;
|
|||||||
|
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
|
import org.apache.cordova.api.CallbackContext;
|
||||||
|
import org.apache.cordova.api.CordovaPlugin;
|
||||||
import org.apache.cordova.api.LOG;
|
import org.apache.cordova.api.LOG;
|
||||||
import org.apache.cordova.api.CordovaInterface;
|
import org.apache.cordova.api.CordovaInterface;
|
||||||
import org.apache.cordova.api.Plugin;
|
|
||||||
import org.apache.cordova.api.PluginResult;
|
import org.apache.cordova.api.PluginResult;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
@ -35,7 +36,7 @@ import android.content.IntentFilter;
|
|||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
|
|
||||||
public class Device extends Plugin {
|
public class Device extends CordovaPlugin {
|
||||||
public static final String TAG = "Device";
|
public static final String TAG = "Device";
|
||||||
|
|
||||||
public static String cordovaVersion = "2.1.0"; // Cordova version
|
public static String cordovaVersion = "2.1.0"; // Cordova version
|
||||||
@ -55,9 +56,10 @@ public class Device extends Plugin {
|
|||||||
* get file paths associated with the Activity.
|
* get file paths associated with the Activity.
|
||||||
*
|
*
|
||||||
* @param cordova The context of the main Activity.
|
* @param cordova The context of the main Activity.
|
||||||
|
* @param webView The CordovaWebView Cordova is running in.
|
||||||
*/
|
*/
|
||||||
public void setContext(CordovaInterface cordova) {
|
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
|
||||||
super.setContext(cordova);
|
super.initialize(cordova, webView);
|
||||||
Device.uuid = getUuid();
|
Device.uuid = getUuid();
|
||||||
this.initTelephonyReceiver();
|
this.initTelephonyReceiver();
|
||||||
}
|
}
|
||||||
@ -65,15 +67,12 @@ public class Device extends Plugin {
|
|||||||
/**
|
/**
|
||||||
* Executes the request and returns PluginResult.
|
* Executes the request and returns PluginResult.
|
||||||
*
|
*
|
||||||
* @param action The action to execute.
|
* @param action The action to execute.
|
||||||
* @param args JSONArry of arguments for the plugin.
|
* @param args JSONArry of arguments for the plugin.
|
||||||
* @param callbackId The callback id used when calling back into JavaScript.
|
* @param callbackContext The callback id used when calling back into JavaScript.
|
||||||
* @return A PluginResult object with a status and message.
|
* @return True if the action was valid, false if not.
|
||||||
*/
|
*/
|
||||||
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
|
||||||
PluginResult.Status status = PluginResult.Status.OK;
|
|
||||||
String result = "";
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (action.equals("getDeviceInfo")) {
|
if (action.equals("getDeviceInfo")) {
|
||||||
JSONObject r = new JSONObject();
|
JSONObject r = new JSONObject();
|
||||||
@ -85,25 +84,15 @@ public class Device extends Plugin {
|
|||||||
//JSONObject pg = new JSONObject();
|
//JSONObject pg = new JSONObject();
|
||||||
//pg.put("version", Device.CordovaVersion);
|
//pg.put("version", Device.CordovaVersion);
|
||||||
//r.put("cordova", pg);
|
//r.put("cordova", pg);
|
||||||
return new PluginResult(status, r);
|
callbackContext.success(r);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return new PluginResult(status, result);
|
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
|
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
|
||||||
}
|
}
|
||||||
}
|
return true;
|
||||||
|
|
||||||
/**
|
|
||||||
* Identifies if action to be executed returns a value and should be run synchronously.
|
|
||||||
*
|
|
||||||
* @param action The action to execute
|
|
||||||
* @return T=returns value
|
|
||||||
*/
|
|
||||||
public boolean isSynch(String action) {
|
|
||||||
if (action.equals("getDeviceInfo")) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user