You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, NativeScript for Android does not support this scenario (at least we haven't tested it). However, this is technically possible and we will provide support for it.
@NathanaelA this issue looks closed however. @slavchev would it be possible to re-open this? Or is there a general ticket covering this issue for IOS and Android? Thanks.
Currently NativeScript runtime for Android (you mentioned jar library) does not support this scenario though it is technically possible. I would suggest to keep this issue closed as there are other issues on this topic, for example #85, with active discussion.
What I didn't realize, is that the com.my.IntentService class will be instantiated even if you killed the app, once you registered it for location updates.
Note: the code is mostly copy & pasted for reference only, it will not work as-is. If you don't manage to figure out the missing parts, please let me know ;)
Also, we are now working on an open source natives script plugin that will allow you to use location tracking in background. The code was copy pasted from that 😄
@surdu
ah right, saw this repo taking the same strategy. Thanks for that.
Also, we are now working on an open source natives script plugin that will allow you to use location tracking in background. The code was copy pasted from that 😄
That'd be awesome, looking forward to seeing that 👍
com.pip3r4o.android.app.IntentService.extend("com.my.IntentService", {
onHandleIntent: function (intent) {
const loc = LocationResult.extractResult(intent).getLastLocation();
}
});`
is this code snippet depend on google play service ? if play service is not available , what is my alternative ? thanks
@c1ngular Yes, it depends on Google Play Services. I believe there are no other alternatives, but I don't think there is an Android phone without Google Play Services ... I mean how do you install the app on the phone otherwise ?
@c1ngularAccording to this you do have an alternative to Google Play Services when it comes to location. I don't know if for that you still have the ability to use it in the background without a continuously running service.
@surdu@christocracy thanks !
I have Google play service on my phone, but most phones in China don't, ! besides the background location , is it possible that I use this background service to send user notifications (Push service) even my app is not running ? Any advice on this approach? Thanks
Activity
abhikmitra commentedon Mar 7, 2015
Yes same question
sunel commentedon Mar 7, 2015
👍
mzalazar commentedon Mar 9, 2015
I need to know the same thing, anybody? ;-)
slavchev commentedon Mar 13, 2015
Currently, NativeScript for Android does not support this scenario (at least we haven't tested it). However, this is technically possible and we will provide support for it.
enchev commentedon May 18, 2015
Please use this issue: #85
gavinengel commentedon May 20, 2015
There are 2 thread referencing each other ... is this ticket issues/2 the main one for commenting on background threads, or is this?: #85
RangerMauve commentedon May 20, 2015
As @enchev said, #85 should be used as the main one, I think.
sgon00 commentedon Aug 4, 2015
+1
If "Native"script can not even create a simple background service, it should not be called "native".
NathanaelA commentedon Oct 22, 2015
pacal commentedon Oct 22, 2015
@NathanaelA this issue looks closed however. @slavchev would it be possible to re-open this? Or is there a general ticket covering this issue for IOS and Android? Thanks.
x4080 commentedon Nov 13, 2015
Is it possible that the service is in a library / jar and running the service from ns?
slavchev commentedon Nov 13, 2015
Currently NativeScript runtime for Android (you mentioned jar library) does not support this scenario though it is technically possible. I would suggest to keep this issue closed as there are other issues on this topic, for example #85, with active discussion.
x4080 commentedon Nov 13, 2015
OK, since its quite different, we must solve these 2 problems I think . notifications is quite important as responsiveness of the ux . thanks
36 remaining items
Liooo commentedon Sep 10, 2017
@surdu does this code still work? I'm using tns-android 3.2, and android.app is not found
Liooo commentedon Sep 10, 2017
Okay got it, for others coming here in the future. If you're using typescript, do the following
npm install tns-platform-declarations --savereference.d.tsdeclare var com;before doingvar intent = new android.content.Intent(context, com.something.SomeService.class);in the example above.surdu commentedon Sep 11, 2017
@Liooo I'm not using this exact code in my app anymore, but it should still work.
I needed it to track locations in background and figured out I don't need a continuously running background service for that.
And yeah, maybe I should have mentioned that that code is written in vanilla JS version of {N} 😅
Liooo commentedon Sep 11, 2017
@surdu thanks for the reply, and yea it will still work for vanilla JS {N}.
Oh I'm doing the same thing, and if we want the location tracking to work even when the app is in the background or killed, we need Service don't we?
(sorry it's bit off track from the original issue tho)
surdu commentedon Sep 11, 2017
@Liooo No, you don't 😄
You need to create am instance of IntentService like so:
You will need this plugin for the above code in order to be able to declare IntentServices with an empty constructor.
Then, when you request for the location updates, you pass the class created above .
What I didn't realize, is that the
com.my.IntentServiceclass will be instantiated even if you killed the app, once you registered it for location updates.Note: the code is mostly copy & pasted for reference only, it will not work as-is. If you don't manage to figure out the missing parts, please let me know ;)
Also, we are now working on an open source natives script plugin that will allow you to use location tracking in background. The code was copy pasted from that 😄
Liooo commentedon Sep 11, 2017
@surdu
ah right, saw this repo taking the same strategy. Thanks for that.
That'd be awesome, looking forward to seeing that 👍
c1ngular commentedon Sep 15, 2017
@surdu
`const LocationResult = com.google.android.gms.location.LocationResult;
com.pip3r4o.android.app.IntentService.extend("com.my.IntentService", {
onHandleIntent: function (intent) {
const loc = LocationResult.extractResult(intent).getLastLocation();
}
});`
is this code snippet depend on google play service ? if play service is not available , what is my alternative ? thanks
surdu commentedon Sep 15, 2017
@c1ngular Yes, it depends on Google Play Services. I believe there are no other alternatives, but I don't think there is an Android phone without Google Play Services ... I mean how do you install the app on the phone otherwise ?
christocracy commentedon Sep 15, 2017
Talk to someone from China or Iran
surdu commentedon Sep 15, 2017
@c1ngular According to this you do have an alternative to Google Play Services when it comes to location. I don't know if for that you still have the ability to use it in the background without a continuously running service.
Here you have some more details: https://stackoverflow.com/a/33023788/460750
christocracy commentedon Sep 15, 2017
If you want an alternative to play-services, with identical API, use this.
https://github.com/mapzen/lost
c1ngular commentedon Sep 16, 2017
@surdu @christocracy thanks !
I have Google play service on my phone, but most phones in China don't, ! besides the background location , is it possible that I use this background service to send user notifications (Push service) even my app is not running ? Any advice on this approach? Thanks
Merge pull request #2 from NativeScript/feature/tab-bar
lock commentedon Aug 27, 2019
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.