Comments (3)
If someone needs, I added "import android.os.Looper" in the top of file BackgroundServicePlugin.java and then I wrapped the code inside new Runnable() with Looper.prepare() and Looper.loop() like this:
cordova.getThreadPool().execute(new Runnable() {
@Override
public void run() {
Looper.prepare();
.......
.......
Looper.loop();
}
});
And it worked!
from bgs-core.
@Kujbor - Thanks for updating the question with a response.
I had a similar problem with the looper when I wrote a GPS plugin (a lot of people use the BGS for this). Apologies for not being able to help at the time.
For reference, I created a Work In Progress GPS plugin - which while not complete - may help if you need further examples. It can be found here -> https://github.com/Red-Folder/GPS-Service-Plugin
from bgs-core.
hey Kujbor, I am trying to do the same thing but i don't the exact code to put inside Looper.prepare() and Looper.loop(). Can you share with me the exact code that you used.
I tried it in a little different way
try{ // Identify a listener that responds to location updates LocationListener
LocationListener locationListener = new LocationListener() {
Handler MAIN_HANDLER = new Handler(Looper.getMainLooper());
public void onLocationChanged(Location location)
{
final Location result = location;
// Called when a new location is found by the network location provider.
MAIN_HANDLER.post( new Runnable() {
@Override
public void run() {
Log.d(TAG, "Location Changed-15");
Log.d(TAG, "Latitude : " + Double.toString(result.getLatitude()));
Log.d(TAG, "Longitude : " + Double.toString(result.getLongitude()));
Log.d(TAG, "Time : " + Long.toString(result.getTime()));
Log.d(TAG, "Accuracy : " + Float.toString(result.getAccuracy()));
}
});
}
public void onStatusChanged(String provider, int status, Bundle extras) {}
public void onProviderEnabled(String provider) {}
public void onProviderDisabled(String provider) {}
};
// Register the listener with the Location Manager to receive location updates
HandlerThread t = new HandlerThread("my handler thread");
t.start();
try{
if(lm.isProviderEnabled(LocationManager.GPS_PROVIDER))
{
Log.d(TAG, "Location Fetching from GPS");
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener,t.getLooper());
}
else
{
Log.d(TAG, "Location Fetching from Network");
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener,t.getLooper());
}
}
catch (SecurityException e) {
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener,t.getLooper());
Log.d(TAG, "This is a Security Exception");
e.printStackTrace();
}
catch(IllegalArgumentException e){
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener,t.getLooper());
Log.d(TAG, "This is an Illegal Argument Exception");
e.printStackTrace();
}
}
catch(Exception e){
Log.d(TAG,"An error occured in forced location fetching");
e.printStackTrace();
}
from bgs-core.
Related Issues (20)
- Error Occurs on startService(success,failed) ;
- Backgound service stops when the app is terminated HOT 2
- creating multiple service class HOT 2
- Does this plugin works with local notifications? HOT 2
- Integrating with NotificationListenerService would it work?
- If Background Service is Running Through Any Local Notification or Alerts?
- Where to put MyService.java in IONIC? Android is unable to find/bind. HOT 2
- Error on Boot
- Its not working in Android 10 HOT 1
- running cordova inside of a service HOT 5
- What is service will not running when app closed ? HOT 8
- It's Possible MyService.java Call Javascript Function ? HOT 3
- ideas to make a service to continue receiving push notifications HOT 2
- Build Android Error HOT 13
- Add method onCleanup to override
- Can I load a third party android library?
- Service starting but restart on exit failing
- Application run but factory is empty
- How to stop a Countdown when the App is backgrounded (Xamarin forms) HOT 2
- Detect the volum up pression in background service
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bgs-core.