cordova-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Joe Bowser (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CB-2273) There is a bug in the android geolocation plugin of Cordova 2.3
Date Thu, 07 Feb 2013 19:33:12 GMT

    [ https://issues.apache.org/jira/browse/CB-2273?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13573831#comment-13573831
] 

Joe Bowser commented on CB-2273:
--------------------------------

See this wiki article on how to contribute:
https://wiki.apache.org/cordova/ContributorWorkflow

That being said, I tested this, but it seems that the GPS is never released when the application
closed.  This code as is introduces issues than it solves.  Can you follow the contributor
workflow and send another pull request?
                
> There is a bug in the android geolocation plugin of Cordova 2.3
> ---------------------------------------------------------------
>
>                 Key: CB-2273
>                 URL: https://issues.apache.org/jira/browse/CB-2273
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Android
>    Affects Versions: 2.2.0, 2.3.0
>         Environment: HTC t328D,Android 4.0.3
>            Reporter: SunshineTech Zhang
>            Assignee: Joe Bowser
>              Labels: patch
>             Fix For: 2.5.0
>
>
> When I call the watchPosition function, it only call back my successCallback function
2 times and errorCallback function once. That is, it call back successCallback function of
getCurrentPosition and watchPosition; and errorCallback function of watchPosition when timeout
event was fired. Then the plugin gives nothing any more.
> Then I read the source code of org.apache.cordova.GeoBroker and org.apache.cordova.CordovaLocationListener.
I found there was an issue in the win and fail method of org.apache.cordova.CordovaLocationListener.
That is, after the listener called its callbacks' by traversal, it then stop itself, so it
doesn't listen position changed information for its watches list.
> So I modify them, the plugin runs well.
> 1. I modify the win and fail method in the org.apache.cordova.CordovaLocationListener
as the following:
> protected void fail(int code, String message) {
>         for (CallbackContext callbackContext: this.callbacks)
>         {
>             this.owner.fail(code, message, callbackContext, false);
>         }
>         if(this.owner.isGlobalListener(this) && this.watches.size() == 0)
>         {
>         	Log.d(TAG, "Stopping global listener");
>         	this.stop();
>         }
>         this.callbacks.clear();
>         Iterator<CallbackContext> it = this.watches.values().iterator();
>         while (it.hasNext()) {
>             this.owner.fail(code, message, it.next(), true);
>         }
>     }
>     private void win(Location loc) {
>         for (CallbackContext callbackContext: this.callbacks)
>         {
>             this.owner.win(loc, callbackContext, false);
>         }
>         if(this.owner.isGlobalListener(this) && this.watches.size() == 0)
>         {
>         	Log.d(TAG, "Stopping global listener");
>         	this.stop();
>         }
>         this.callbacks.clear();
>         Iterator<CallbackContext> it = this.watches.values().iterator();
>         while (it.hasNext()) {
>             this.owner.win(loc, it.next(), true);
>         }
>     }
> 2、I modify the win and fail method in the org.apache.cordova.GeoBroker as the following:
> public void win(Location loc, CallbackContext callbackContext, boolean keepCallback)
{
>     	PluginResult result = new PluginResult(PluginResult.Status.OK, this.returnLocationJSON(loc));
>     	result.setKeepCallback(keepCallback);
>         callbackContext.sendPluginResult(result);
> }
> public void fail(int code, String msg, CallbackContext callbackContext, boolean keepCallback)
{
>         JSONObject obj = new JSONObject();
>         String backup = null;
>         try {
>             obj.put("code", code);
>             obj.put("message", msg);
>         } catch (JSONException e) {
>             obj = null;
>             backup = "{'code':" + code + ",'message':'" + msg.replaceAll("'", "\'") +
"'}";
>         }
>         PluginResult result;
>         if (obj != null) {
>             result = new PluginResult(PluginResult.Status.ERROR, obj);
>         } else {
>             result = new PluginResult(PluginResult.Status.ERROR, backup);
>         }
>         result.setKeepCallback(keepCallback);
>         callbackContext.sendPluginResult(result);
>     }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message