Red-Folder / bgs-core

Core code for the Cordova Background Service
Other
236 stars 103 forks source link

error: reference to put is ambiguous, both method put(String,Collection) in JSONObject #33

Closed mm108 closed 7 years ago

mm108 commented 9 years ago

hi,

Thanks a lot for the background services plugin. I am trying to use this in one my apps and this is what I encounter when I try to build the package

/src/com/red_folder/phonegap/plugin/backgroundservice/BackgroundServicePluginLogic.java:[711,16] error: reference to put is ambiguous, both method put(String,Collection) in JSONObject and method put(String,Map) in JSONObject match

/src/com/red_folder/phonegap/plugin/backgroundservice/BackgroundServicePluginLogic.java:[712,16] error: reference to put is ambiguous, both method put(String,Collection) in JSONObject and method put(String,Map) in JSONObject match

/src/com/red_folder/phonegap/plugin/backgroundservice/BackgroundServicePluginLogic.java:[713,16] error: reference to put is ambiguous, both method put(String,Collection) in JSONObject and method put(String,Map) in JSONObject match

/src/com/red_folder/phonegap/plugin/backgroundservice/BackgroundServicePluginLogic.java:[714,16] error: reference to put is ambiguous, both method put(String,Collection) in JSONObject and method put(String,Map) in JSONObject match

I am pretty new (more like totally new) to java and if you could give me some hint on how to solve this, It'd be great.

Thanks once again for the plugin.

Note: All I mainly need is a background service that runs on Android and executes a timer event - say once 30 seconds.

Cheers, M&M

Red-Folder commented 9 years ago

What version of Java are you using?

mm108 commented 9 years ago

hi,

Thanks for the super quick response :-) I am using appery.io (https://appery.io/) Its a hosted mobile app development solution. So I am a little clueless on the exact version of java. I can get em to respond on the forum and get the version.

Thanks, M&M

Red-Folder commented 9 years ago

Ok, try and find out the Java & Android version

I'd guess that it is something odd within the Appery setup. I've never used it and wouldn't be confident in it working.

mm108 commented 9 years ago

hi,

Oke thanks. I already pinged them. As for Android the version is 4.3. I will get back to you with the version of java.

Thanks once again, M&M

mm108 commented 9 years ago

hi,

I got a reply from them - Appery.io runs on Java7

Btw this Appery supports third party plugins (cordova/phonegap etc). I have been able to get many plugins to work in Appery. I am not sure whether is a deprecated method or something that's causing the problem. I am a total noob to java :)

thanks, M&M

Red-Folder commented 9 years ago

From what I can see, most responses to that sort of error are bug in the compiler. Certainly I've seen mention of Java 7 having a bug in it that causes this (reference here http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6199075)

Check with Appery if their Java version is post that fix.

mm108 commented 9 years ago

hi,

do you think I can typecast the null values in lines 711 -> 714? Or not put null at all? My experience with java is almost nil. So please don't mind me asking something that might seem fundamental.

Thanks a ton for your help so far.

Cheers, M&M

Red-Folder commented 9 years ago

Try casting them to a string:

(String) null;

Be good to know if that works as I've no way to replicate

mm108 commented 9 years ago

hi,

I did this

try { result.put("ServiceRunning", false); } catch (Exception ex) {Log.d(LOCALTAG, "Adding ServiceRunning to JSONObject failed", ex);}; try { result.put("TimerEnabled", "null"); } catch (Exception ex) {Log.d(LOCALTAG, "Adding TimerEnabled to JSONObject failed", ex);}; try { result.put("Configuration", "null"); } catch (Exception ex) {Log.d(LOCALTAG, "Adding Configuration to JSONObject failed", ex);}; try { result.put("LatestResult", "null"); } catch (Exception ex) {Log.d(LOCALTAG, "Adding LatestResult to JSONObject failed", ex);}; try { result.put("TimerMilliseconds", "null"); } catch (Exception ex) {Log.d(LOCALTAG, "Adding TimerMilliseconds to JSONObject failed", ex);};

but it doesn't work. I was expecting to see the alert. And also on my Android 4.3 I don't see it in the list of running applications.

To test I used the sample code from your github page

var myService;

document.addEventListener('deviceready', function() { myService = cordova.plugins.myService;; go(); }, true);

function go() { myService.getStatus(function(r){startService(r)}, function(e){handleError(e)}); };

function startService(data) { if (data.ServiceRunning) { enableTimer(data); } else { myService.startService(function(r){enableTimer(r)}, function(e){handleError(e)}); } }

function enableTimer(data) { if (data.TimerEnabled) { allDone(); } else { myService.enableTimer(60000, function(r){allDone(r)}, function(e){handleError(e)}); } }

function allDone() { alert("Service now running"); }

in my cordova_plugins.js the clobbers / path looks like this { "file": "plugins/com.red_folder.phonegap.plugin.backgroundservice/www/backgroundService.js", "id": "com.red_folder.phonegap.plugin.backgroundservice", "clobbers": [ "myService" ] }

which is very much in sycn with what I have done with some other plugins. Btw Appery io offers free account wherein you can create upto 3 apps with a max of 3 pages each. They have tutorials on how to incorporate cordova / phonegap / third party plugins into their MBaaS

https://devcenter.appery.io/documentation/using-native-device-features-phonegap/#Adding_an_NFC_plugin

I'd appreciate any help you could offer as my app greatly depends on being able to run my app as a background service.

Thanks & cheers, M&M

mm108 commented 9 years ago

hi Mark,

Keeping everything aside say I just want a simple service that runs in the background and triggers a timer every 30 seconds, what will be the minimal files that I will be using? I am totally new to Java so having some leads will help. I am not that keen on having the above problem sorted out - all i need is a minimal working background service.

Cheers, M&M

Red-Folder commented 9 years ago

I can't see a problem with the above code.

You'll need to put some form of debugging into it to see what it is doing. Add alerts to each function to make sure they are being run as well and return any data you are getting.

I would expect the answer to be buried in their somewhere.

I'm afraid I have no plans to spend time on Appery (or Build for that matter). The automated build services simply don't interest me and I've got too many other things on to get to grips with them.

mm108 commented 9 years ago

hi Mark,

Okie thanks. Lemme fiddle around with the stuff and see if i can get anything going. Thanks a ton for your time so far. Really appreciate you reply, responses. If I am able to pull this off I'd get you a beer for sure :-)

Cheers, M&M

mm108 commented 9 years ago

Just a quick question mark (hopefully not a stupid question too)

To be able to use this plugin do I need to use both these? https://github.com/Red-Folder/bgs-core/tree/121056366c04b79b0423aa75065ae38ec279fff6 https://github.com/Red-Folder/bgs-sample

Thanks a ton, M&M

Red-Folder commented 9 years ago

If you are trialing the plugin using the myService example, then yes.

If you are building your own background service (that does more than says "Hello world") then you would only need the bgs-core and your own background service.

The bgs-core plugin provides the core logic for the background service - but doesn't nothing itself. You need to have a background service written to actually do anything useful. The background service you write uses the bgs-core to do most of the heavy lifting.

In bgs-sample (which has the myService background service, as well as a simple app front-end) is, as the name suggests, a sample background service. In a production application you would write your own background service and not use the bgs-sample.

I hope that helps.

Red-Folder commented 9 years ago

An example of a background service that does something is the GPS plugin -> https://github.com/Red-Folder/GPS-Service-Plugin

It is still work in progress (not even sure if it compiles) - but if you look at the plugin.xml, you will see that it uses the bgs-core as it's dependency.

It then has its own background service implementation which does something useful (or will do when I finish it) - gets the users current GPS position and pushes it to a webserver.

mm108 commented 9 years ago

hi,

Thanks a lot for the explanation. I am starting to understand how the bgs-core and the sample service works.

Got into uncharted territory because a sudden need arose to write a background service for transferring files in the background and also upload device geo-location to a server. Just getting acquainted with java for the first time in life. I think that explains my hiccups :)

Thanks once again, M&M

henryemekaofozor commented 8 years ago

We really need the GPS SERVICE part