vliesaputra / DeviceInformationPlugin

This plugin allows you to retrieve most information about your Android devices that are available through Android's Telephony Manager class from your PhoneGap application.
MIT License
47 stars 31 forks source link

Works with phonegap 2.2? #5

Open dblanco16 opened 10 years ago

dblanco16 commented 10 years ago

Try to implement this plugin on a project with phonegap 2 .. 2.

In java change:

org.apache.cordova.api.CallbackContext import; org.apache.cordova.api.CordovaPlugin import; org.apache.cordova.api.PluginResult import;

Compiles ok.

In HTML use:

var deviceInfo = cordova.require("cordova/plugin/DeviceInformation"); alert('start'); deviceInfo.get(function(result) { alert("result = " + result); }, function() { alert("error"); }); alert ('final');

But dont alert "start".

More info:

How should initialize the variable deviceInfo ? thanks

vliesaputra commented 10 years ago

I don't think your changes in java would compile properly as the code requires all of those libraries to work properly.

I haven't tried this but according to phonegap2.2 API, you should only need to update the execute method in deviceinformation.java to something like this:

           public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
                          if (action.equals("get")) {
                                         TelephonyManager tm = (TelephonyManager)  this.cordova.getActivity().getSystemService(Context.TELEPHONY_SERVICE);
                                         AccountManager am = AccountManager.get(this.cordova.getActivity());

                                          String result = getDetails(tm,am);
                                          if (result != null) {
                                                         callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result));
                                                         return true;
                                         }
                         }
                         callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR));
                         return false;
        }
dblanco16 commented 10 years ago

Dont work that change