Closed Voyager2718 closed 7 years ago
How have you installed it? Have you installed with the "cordova plugin add ...." command?
It sounds from the above like it cannot find the plugin files - that maybe because they are in the wrong location in the project (should be ok if you used the cordova plugin add command because it handles it all for you).
If you haven't already, have a go with the sample background service plugin - that should help make sure everything is wired up correctly. See https://github.com/Red-Folder/bgs-core/wiki/Using-the-MyService-Sample
Hope that helps
Of course I have.
The problem is: when I change to cordova.require('com.red_folder.phonegap.plugin.backgroundservice.backgroundService');
, Chrome gives me
app.bundle.js:34510 EXCEPTION: Error: Uncaught (in promise): module com.red_folder.phonegap.plugin.backgroundservice.backgroundService not found
.
But when I use cordova.require('com.red_folder.phonegap.plugin.backgroundservice.BackgroundService');
, there's no problem but cordova.require
still returns nothing.
Here's the structure of my folders.
What's more, I've added <service>
to my AndroidManifest.xml
as well as I've created my own service that extends BackgroundService
.
What may be the cause of the problem? Because I really followed your sample project.
Ok, do you have your code available in a public repo?
When you say require returns nothing - do you mean null or undefined?
It's been a while since I've used the plugin - but my sample isn't prefixing require with cordova:
var serviceName = 'com.red_folder.phonegap.plugin.backgroundservice.sample.MyService';
var factory = require('com.red_folder.phonegap.plugin.backgroundservice.BackgroundService');
module.exports = factory.create(serviceName);
Actually I'm using it on Inoic 2. Does your project support Ionic 2?
Here's my testing project. https://github.com/Voyager2718/test_cordova_background_service
Could you please see how can I use your work in my Ionic 2 project?
I've no experience with Ionic 2. I'd suggest you have a search on Google for advice (if any) on using Cordova Plugins with Ionic. I had previously believed they would just work - but having never used Ionic then I could provide any confidence.
One comment I do have from reading the above; you talk about Chrome. I assume you are using Chrome to develop & test your web app. Please keep in mind that you will not be able to use BGS within Chrome - it is expecting an Android environment to run the Java - this is not possible in Chrome. I doubt that this is your current problem - as you should still get the plugin - you just wouldn't be able to use it,
just reading your code (index.html) - it has the following:
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
Is the comment being put in by Ionic? Does this mean that cordova isn't available during development (ie. in Chrome as you seem to be working in).
As I say I have zero experience with Ionic, but this would seem to suggest that cordova isn't available during development. And if cordova isn't available, then neither will be the plugins.
One final comment;
I cannot actually see where in the above reference project you are doing anything with the plugin. You appear to installed BGS-Core - but then haven't created a background service to use it.
I'd expect a .js and .java file at minimum which is your background implementation.
Am I missing it? (I only did a quick skim)
Actually I put my Java files here: https://github.com/Voyager2718/test_cordova_background_service/tree/master/plugins/com.red_folder.phonegap.plugin.backgroundservice/src/android
Is that correct? Do you have a sample project that allows me to have a look? Because I followed your tutorial, but it seems not work for me.
I used Chrome to inspect App that runs on my device. Because Ionic actually runs on WebView, so that Chrome can inspect them. However, it seems doesn't work for me.
BGS-Core will never work in Chrome. It needs the Android environment
In terms of sample project, use bgs-sample - details of how to use are explained here -> https://github.com/Red-Folder/bgs-core/wiki/Using-the-MyService-Sample
Finally it works on my device. But another problem appears.
I would like to detect iBeacons and send notifications when have detected an iBeacon that we had provided. I don't know how can I import related libraries such as import android.bluetooth.BluetoothAdapter;
or import android.app.Notification;
.
I would like to use create background services for my Ionic 2 app. So that I choose this plugin.
In my
com.red_folder.phonegap.plugin.backgroundservice
folder, I haveAnd in
/src/android
, I have/beaconListener
and a bunch of original background service .java files.So I wrote
BeaconService.java
which extendsBackgroundService
in/beaconListener
.Then I require it by using
in my corresponding TypeScript file.
However, I found that
cordova.require()
returns nothing all the time. So that I can't get the object that I need.What's wrong with my background service? Why couldn't I get the object that I want?