-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dosen't work on Android 5.0 #18
Comments
Amend the BackgroundServicePluginLogic.java, from (line 601):
to
Unable to test at the moment, but I'll have a go when I've sorted my development environment. The code could definitely be better, but (fingers crossed) this does the trick for you. Very keen to hear how well it works (or doesn't) |
Sorry ... should have mentioned, amend the two variables to reflect your package and class name:
|
Hello Mark, thank you for your quick answer. but your trick unfortunately doesn't fix the problem :( Here is the log: 10-27 22:42:46.710: D/BackgroundServicePluginLogic(858): Start of Execute |
We seem to be getting a different error. Original problem was failing on bind ... now we seem to be getting further. Can I just check, what values are you using for packageName & className? |
Here are the names String packageName = "com.domain.demoapp"; => the MyService (in my case the push service) is under the package "com.domain.demoapp" in the file MyService.java With Android 4.4 and lower it works... When I build a empty app like in your tutorial, its the same problem under Android 5 |
Try changing the lines to: this.mService = new Intent(); |
which line should I change with the new one? |
I replaced line 601 (original file) with your two lines Error: |
Sorry - my fault. I misread the Android documents. I hope to have my development environment working tonight (spent the last two evenings getting it up to Android 5). So will investigate this issue for fully. |
Yes I know, to build a good working development environment is sometimes tricky. I waiting eagerly to test the patched plugin. I would also like to thank you for the speedy response ;) |
Hello, |
I resolved by changing the line Tested in nexus 4 with android 5.0 and Sony Xperia L with android 4.2.2 But when i reboot the phone in the sony keep the service running but in the nexus the service status is "Not running" |
For the reboot problem i resolved changing this lines in BootReceiver.java for (int i = 0; i < serviceList.length; i++) to Intent serviceIntent = new Intent(context, MyService.class); I suppose that this changes only work if i have only that service |
@niarferuto Thank you so much for the providing you fix. This is greatly appreciated. I'm still struggling to rebuild a development environment that works. I cannot get the 5.0 emulator to start and interest with Eclipse reliably. My development kit may just be getting too old for it now - which is causing me problems maintaining the plugin (as seen by how long this issue has been unaddressed). Regarding your last comment; I would expect that you can use reflection to MyService.class from the serviceList[i] |
Finally have my development environment working again (just) I'm currently unable to replicate the issue. I've created a Cordova Project, added the bgs-sample plugin (which includes bgs-core), set the Android target to 5.0.1 and run on a 5.0.1 emulator. I'm not getting any errors. |
It's crazy that it work for you, but on my system the problem is still there. I use the newest version of eclipse on osx and like you Android target and emulator 5.0.1. The cordova version is 3.1.0, because the compatibility with other plugins. The service is under a other path. It worked like charmed under Android 5 with the changes of niarferuto, when I write the absolute path of the class like "com.domain.demoapp.MyService.class" When I test it with real phones and android 5 it's like in the emulator, without the changes of niarferuto the service does not start. @niarferuto |
@apollon0815 Could you post the contents of your AndroidManifest.xml (specifically the service section). I expect to implement the code from @niarferuto - but my development environment is proving to be a real struggle. |
Hello Red ;) here is the content of my xml file:
|
You need to make sure you set your This may be helpful: |
@lylepratt I'd seen that article - but thanks anyway I'll try with the targetSdkVersion, see if that allows me to recreate. I'm rebuilding my development environment (again) in an attempt to actually be able to run an emulator properly - so hopefully I can get back on to this soon. I've a few other bugs I'd like to fix - along with some refactor work - hopefully get this done over the Christmas period. |
I'm to the point where I am forced to update to sdk version 21. Now that I have, i'm back to this problem. Anyone have any advice? |
Hi, I am working with the last version of this plugin and the last version of apache cordova. I have a problem with this plugin in Android 5, Nexus 5. I tested the plugin with the example https://github.com/Red-Folder/bgs-core/wiki/Using-the-MyService-Sample and It doesn´t work. When I press the button Service, I receive the next error: Plugin unable to bind background service. The same example works in android 4.4 (Nexus 5), adroid ice-cream and android jelly bean. |
Thank you so much niarferuto. I solved the problem with your corrections. |
Finally I can replicate this Needed build against V21 (app & cordovalib) and run against V21 emulator. Now to fix it |
Fixed in commit 167a4f7 Tested on emulator versions:
|
Thank you so much Red-Folder! ;) |
Hi! Someone could help me? |
Hello Red-Folder, I'm currently trying to use your tutorial to create a background service for my android application. I have used the exact same names as you have, because i wanted to get it to work in the first place. I get the exact same errormessage as mentioned above. Plugin unable to bind to background service. I've tried all the fixes mentioned above as well, but it does not fix the problem. I have been stuck with this problem for a few days now and i now hope you can help me any further, any chance you see what the problem is? The code i currently have on line 601 in the file BackgroundServicePluginLogic.java is, as mentioned above by niarferuto:
i've also tried the solutions you mentioned. But they don't fix my problem. |
Hello to everyone, i am facing the same problem with MarkVlamPersie. Is there a workaround? The version of BackgroundServicePluginLogic.java that i have is already corrected according to above fixes, but still my app says "Plugin unable to bind to background service" Thank you very much. |
Fovaka1, I have opened a thread on Stackoverflow for this. Since JugnuPathak who opened a new issue seems to face the same problem. Would be nice if you could upvote this. Also if you do run into a solution can you post it here? |
Thank you for pointing out. In case of a solution i will post here also, yes. |
Found it!!!!:) Firstly check that you have package com.red_folder.phonegap.plugin.backgroundservice.BackgroundService;inside MyService.java on top. I did not notice that was missing. After you do that go to file com.red_folder.phonegap.plugin.backgroundservice.BackgroundService.BackgroundServicePluginLogic.java line 163 and change String serviceName = data.getString(0); to String serviceName = "com.red_folder.phonegap.plugin.backgroundservice.BackgroundService.MyService"; Otherwise i followed below steps(i did this one first and is working but i think the above could be also a solution, so as not to change files, positions etc..).
2.MyService.java is the following
line 163 and change String serviceName = data.getString(0); to String serviceName = "com.my.app.MyService"; i hope to help you!!! |
Hmmm, I've tried your solution, and it doesn't work for me. but i think i haven't implemented it in the right way.
Now my MyService.java class looks like:
You said to set the package to: I've put that as the package as well as on top of the package. But neither fix the problem. And my android manifest looks like:
Then as you said, i changed line 163 in BackgroundServicePluginLogic.java to: Is there anything i've done wrong or missed from you solution? |
Try this, get your MyService.java file and put it inside your main directory com.my.app change package of course accordingly. change manifest accordingly leave line 163 in BackgroundServicePluginLogic.java as was before and just put this inside app.js var serviceName = 'com.my.app.MyService'; |
I've tried it, but it doesn't fix my issue. What android and cordova version are you using? |
Tested with Android Devices 4.3 and 5.1 and both work just fine. Cordova version 6.1.1 Take android folder (IONIC) and open it with Android Studio. Try the above changes again. |
@fovaka1 it wont work for me. I'll try starting a new project and see if it works there. Thanks for your clear instructions though! |
@MarkVlamPersie @fovaka1 Thanks for contributing you comments to the issue. |
@Red-Folder unfortunately it still won't work for me. Do you have any suggestions on changes that could fix it? I have followed your instructions from the tutorial and i've tried it multiple times but it wont work. I've tried multiple fixes my self. Few things i have noticed so far are:
Then after building, i looked up the same file in the platforms/android directory and found the file like this:
|
I've now finally got it to work. The problem was that MyService.java was excluded from the build when i used the command: Thanks for all the help. |
@MarkVlamPersie Great news that its working. Could I ask a favour please Could you review the documention -> https://github.com/Red-Folder/bgs-core/wiki/Using-the-MyService-Sample If there are changes you feel that would be appropriate given you experience it would be much appreciated. Thanks |
@Red-Folder Sure! I will take a look at it this evening if i can find the time. If not i'll do it tomorrow. |
@Red-Folder Firstly, sorry for very delayed response. I haven't worked with that documentation since i used the tutorial to implement the backgroundservice in my application. I think this documentation is very clear. The only thing that i could possibly think of to edit to the tutorial documentation is to provide the package for you example in code lines. In step 2 something similar to: Also the documentation is still up-to-date and the plugin should work if you implement it correctly(, unlike me). That's basicly all i can say, since the documentation is very clear and most of the code quite self explanatory. |
hi, Mark can u help me please. I've tried your solution, and it doesn't work for me. but i think i haven't implemented it in the right way. --------------->aidl Now my MyService.java class looks like: package com.red_folder.phonegap.plugin.backgroundservice.sample; import com.red_folder.phonegap.plugin.backgroundservice.BackgroundService; import android.util.Log; public class MyService extends BackgroundService { I've put that as the package as well as on top of the package. But neither fix the problem. And my android manifest looks like:
Then as you said, i changed line 163 in BackgroundServicePluginLogic.java to: Is there anything i've done wrong or missed from you solution? what i go next from this position can u guide me.?? Error: Plugin unable to bind to background service and ErrorCode: -4, Success: false, RegisteredForUpdates:false,RegisteredForBootStart:false,ErrorMessage: Plugin unable to to bind to background service,ServiceRunning: false i spend couple of days on this to solve the problem. |
Hey MarkVlamPersie, I've now finally got it to work. The problem was that MyService.java was excluded from the build when i used the command: ionic build android. I have fixed this problem litteraly by just putting MyService.java in the build directory with the other java-files. |
@MarkVlamPersie im tryingall possible solutions but its still not working. |
Hey @nitzpb , I have not worked with this plugin for about a year now, so i find it a bit hard to remember everything i did since i do not have the source code itself anymore. You seem to have taken the right steps. My problem was that i when i used the build command a few Java files were excluded. What you need to do is take a look in the build folder after you have used the build command and see if all the Java files that are in your project also are in the build folder. If some are missing you need to copy those java files from your project to the build folder. E.g. for me the MyService.java was excluded from the build and it was not in the build folder after using the build command, so i copied the MyService.java from the source folder to the build folder. That was what solved the problem for me. I hope this helps you with your problem. |
finally, its solved. |
Thank u for Ur reply.
I manage that issue.
Actually, I'm missed the MyService.js file to add in plugin.
When I add that file and re-install the bg-core plugin its works.
Thank u for uploading this helpful plugin on github.
And
Sorry for my bad English.
Regards,
Niteen Bhende.
…On Jun 16, 2017 3:29 PM, "Mark van der Woude" ***@***.***> wrote:
Hey @nitzpb <https://github.com/nitzpb> ,
I have not worked with this plugin for about a year now, so i find it a
bit hard to remember everything i did since i do not have the source code
itself anymore. You seem to have taken the right steps.
My problem was that i when i used the build command a few Java files were
excluded. What you need to do is take a look in the build folder after you
have used the build command and see if all the Java files that are in your
project also are in the build folder. If some are missing you need to copy
those java files from your project to the build folder. E.g. for me the
MyService.java was excluded fromt the build and i was not in the build
folder after using the build command, so i copied the MyService.java from
the source folder to the build folder. That was what solved the problem for
me.
I hope this helps you with your problem.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#18 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AQU26lGCUpubbUaTvN9e0ZqK8kxikuWhks5sElIGgaJpZM4Cyq8M>
.
|
This service Not working in Android 10. any help ? |
Hello,
thank you for this wonderful plugin.
It works very well on Android 4.4 and lower.
But when I test it with Eclipse and Android 5 SDK on an Android 5.0 emulator, background service not starting.
I hope you can fix it.
Thank you very much.
Log:
10-24 14:46:58.119: D/BackgroundServicePluginLogic(1206): Start of Execute
10-24 14:46:58.120: D/BackgroundServicePluginLogic(1206): Withing try block
10-24 14:46:58.122: D/BackgroundServicePluginLogic(1206): Finding servicename com.domain.demoapp.MyService
10-24 14:46:58.122: D/BackgroundServicePluginLogic(1206): Services contain 0 records
10-24 14:46:58.123: D/BackgroundServicePluginLogic(1206): Creating new Service Details
10-24 14:46:58.132: W/PluginManager(1206): THREAD WARNING: exec() call to BackgroundServicePlugin.getStatus blocked the main thread for 231ms. Plugin should use CordovaInterface.getThreadPool().
10-24 14:47:00.176: W/PluginManager(1206): THREAD WARNING: exec() call to File.getFile blocked the main thread for 264ms. Plugin should use CordovaInterface.getThreadPool().
10-24 14:47:03.076: D/BackgroundServicePluginLogic(1206): Action = getStatus
10-24 14:47:03.211: D/BackgroundServicePlugin(1206): logicResult = com.red_folder.phonegap.plugin.backgroundservice.BackgroundServicePluginLogic$ExecuteResult@389df6c2
10-24 14:47:03.251: D/BackgroundServicePlugin(1206): Start of transformResult
10-24 14:47:03.266: D/BackgroundServicePlugin(1206): Status is OK
10-24 14:47:03.267: D/BackgroundServicePlugin(1206): We have data
10-24 14:47:03.269: D/BackgroundServicePlugin(1206): End of transformResult
10-24 14:47:03.270: D/BackgroundServicePlugin(1206): pluginResult = org.apache.cordova.PluginResult@187d5cd3
10-24 14:47:03.272: D/BackgroundServicePlugin(1206): pluginResult.getMessage() = {"Success":true,"ErrorCode":0,"ErrorMessage":"","ServiceRunning":false,"RegisteredForBootStart":false,"RegisteredForUpdates":false}
10-24 14:47:03.272: D/BackgroundServicePlugin(1206): Dont keep Callback
10-24 14:47:04.200: D/BackgroundServicePluginLogic(1206): Start of Execute
10-24 14:47:04.201: D/BackgroundServicePluginLogic(1206): Withing try block
10-24 14:47:04.202: D/BackgroundServicePluginLogic(1206): Finding servicename com.domain.demoapp.MyService
10-24 14:47:04.366: D/BackgroundServicePluginLogic(1206): Services contain 1 records
10-24 14:47:04.367: D/BackgroundServicePluginLogic(1206): Found existing Service Details
10-24 14:47:04.368: D/BackgroundServicePluginLogic(1206): Action = startService
10-24 14:47:04.368: D/ServiceDetails(1206): Starting startService
10-24 14:47:04.368: D/ServiceDetails(1206): Attempting to bind to Service
10-24 14:47:04.369: D/ServiceDetails(1206): Starting bindToService
10-24 14:47:04.427: D/ServiceDetails(1206): Attempting to start service
10-24 14:47:04.632: D/ServiceDetails(1206): bindToService failed
10-24 14:47:04.632: D/ServiceDetails(1206): java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.domain.demoapp.MyService }
10-24 14:47:04.632: D/ServiceDetails(1206): at android.app.ContextImpl.validateServiceIntent(ContextImpl.java:1674)
10-24 14:47:04.632: D/ServiceDetails(1206): at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1703)
10-24 14:47:04.632: D/ServiceDetails(1206): at android.app.ContextImpl.startService(ContextImpl.java:1687)
10-24 14:47:04.632: D/ServiceDetails(1206): at android.content.ContextWrapper.startService(ContextWrapper.java:515)
10-24 14:47:04.632: D/ServiceDetails(1206): at com.red_folder.phonegap.plugin.backgroundservice.BackgroundServicePluginLogic$ServiceDetails.bindToService(BackgroundServicePluginLogic.java:604)
10-24 14:47:04.632: D/ServiceDetails(1206): at com.red_folder.phonegap.plugin.backgroundservice.BackgroundServicePluginLogic$ServiceDetails.startService(BackgroundServicePluginLogic.java:335)
10-24 14:47:04.632: D/ServiceDetails(1206): at com.red_folder.phonegap.plugin.backgroundservice.BackgroundServicePluginLogic.execute(BackgroundServicePluginLogic.java:188)
10-24 14:47:04.632: D/ServiceDetails(1206): at com.red_folder.phonegap.plugin.backgroundservice.BackgroundServicePlugin$1.run(BackgroundServicePlugin.java:68)
10-24 14:47:04.632: D/ServiceDetails(1206): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
10-24 14:47:04.632: D/ServiceDetails(1206): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
10-24 14:47:04.632: D/ServiceDetails(1206): at java.lang.Thread.run(Thread.java:818)
10-24 14:47:04.653: D/ServiceDetails(1206): Finished bindToService
10-24 14:47:04.654: D/ServiceDetails(1206): Bind Failed
10-24 14:47:04.655: D/ServiceDetails(1206): Finished startService
10-24 14:47:04.656: D/BackgroundServicePlugin(1206): logicResult = com.red_folder.phonegap.plugin.backgroundservice.BackgroundServicePluginLogic$ExecuteResult@3ddb0010
10-24 14:47:04.656: D/BackgroundServicePlugin(1206): Start of transformResult
10-24 14:47:04.656: D/BackgroundServicePlugin(1206): Status is ERROR
10-24 14:47:04.657: D/BackgroundServicePlugin(1206): We have data
10-24 14:47:04.657: D/BackgroundServicePlugin(1206): End of transformResult
10-24 14:47:04.657: D/BackgroundServicePlugin(1206): pluginResult = org.apache.cordova.PluginResult@2ca41709
10-24 14:47:04.658: D/BackgroundServicePlugin(1206): pluginResult.getMessage() = {"Success":false,"ErrorCode":-4,"ErrorMessage":"Plugin unable to bind to background service","ServiceRunning":false,"RegisteredForBootStart":false,"RegisteredForUpdates":false}
10-24 14:47:04.658: D/BackgroundServicePlugin(1206): Dont keep Callback
The text was updated successfully, but these errors were encountered: