Android Get Current Location Continuously | Location Service | Fused Location Provider API
ฝัง
- เผยแพร่เมื่อ 13 ก.ย. 2024
- Android Get Current Location Continuously | Location Service | Fused Location Provider API
In this tutorial, we will implement a foreground location service which will give us continuous location updates using the fused location provider API.
For more exciting android tutorials, please subscribe to my TH-cam channel and hit the bell icon for notifications.
android location service, android track location, android location updates, android location service android, android get current location continuous, android location periodically, chirag kachhadiya, kachhadiya chirag, android get current location, get current location android, get current location android studio, android studio get current location, android get current location tutorial, android studio location service, location service in android, location service android
[Important] Android permissions is updated and for API 29 or higher, "ACCESS_BACKGROUND_LOCATION" permission is required as well along with FINE and COARSE location permissions.
Thank You Sir. You code so clean please continue making such video and try to add audio explanation if possible. You really helped me.
Very Good!!!
But just a suggestion for you......You should speak while making tutorials.
Thanks a lot it worked
Огромная человеческая благодарность!
Thanks for the turorial. It helps me a lot on my project.
Great job! Thanks for your explanation, it was very helpful.
oh man , you save my day and my life , appreciated , thank you ! do you have tutorial about Google Fit?
its perfect bro thank you so much.
thank you sir
So far the most helpful location update video
I know im randomly asking but does someone know a way to log back into an Instagram account?
I was dumb forgot the login password. I would appreciate any help you can offer me.
@Bodie Ernest Instablaster :)
@Draven Omar i really appreciate your reply. I found the site thru google and Im in the hacking process now.
Takes quite some time so I will reply here later with my results.
@Draven Omar it worked and I finally got access to my account again. I am so happy!
Thank you so much, you saved my account :D
@Bodie Ernest glad I could help :D
This works great. Thank you so much
great tutorial
Sir, thank you very much !!!, one question: if I restart the phone, the app will start too? if not, how can I get that ?
Set a broadcast receiver to know when the phone has been rebooted then if it has, start the location service.
Thanks sir Its very helpful to me
Good job Man 😊
thanks bro save my time
Well superb but why not you provide project repo
Thanku for this tutorial.
Also plzz make video on google fit
Yes Sir
I have a question - Instead of getting Lat n Long in Log.d, can u show me how to display it on the app screen in Textview? I can't seem to get it done correctly. Other than that, great tutorial, Just wish you would explain, atleast as notepad writings or something. Thanks for the video!
I'm stuck at this as well , any progress ?
@@ziedorabi7534 did you solve? if you did please tell me how
Useful Tutorial
Good job! But it's not fully completed, we have to get result in activity/fragment/custom view. What channels do you use for that? EventBus or something more modern?
You can use intent service or local broadcast manager as well.
Thanks a lot. It's very good.
nice work.. very workfull
nice tutorial, bro
I have created tracking app which runs perfectly in android 7 in background but not running in 8+
Any solution?
What android studio you are using bro... it was awesome??
It's a theme plugin called material UI.
Excellent...
how this app is getting location in the background when we allow it "only while using the app" location permission
also, I have noticed that it's not getting location in background after few seconds
Thank you Sir!
The code helped me a lot.
how do we pass this data to main activity means the one from which the location service call ran
Yo bro you saved my life and job lmao
Can u please make a tutorial on Google fit Integration
How i pass the location double value co-ordinate to other activity and set it to text view. PLEASE REPLY
Sir location share is working in version 13 in background also but that app is not working in any other version like lower then Android 13 version please give me a solution for this sir,🥺
Great tutorial!!!!
does it work in background?
hi how if i want to add marker on Latlng and pass the data in to the components thanks
You got solution?
Because I'm facing same problem.
Thanks a lot man !
sir after using this code the accuracy of location is not fine...this code uses which feature .. GPS provider or Network Provider??...I think gps will have more accuracy
06:19 to 06:21 there is a problem in the code line numbers maybe you imported something but the video does not show that
Thanks
I got error in (Constants.LOCATION_SERVICE_ID), location-service-id is not recognized. help plzz
Thanks, can you make tutorial to get Country \ City name?
excelente!!!!!
This code is not working on above API level 28.... please help me sir
Thank you Sir...but how to add iduser login on the location service?
verry nice
can u tell me what theme u install for ur android stud please ?
It's a plugin for android studio called Material Theme UI.
Hii Dear all how are you? I hope you all will be fine.
I am facing null lat/long issue as i am using fusedlocationproviderclient...
If mobile GpS button is enabled then i get location.. if i disable or reEnable it then i get null location.. if if i close or open app again and again
Is there any other service or anything instead of this which works fine??
Working fine with Android 8,9
But how to get background location above android 10?
It works fine till 1-2 min after that it stops getting the location.
@@apurvadiwe7237 When I open other applications like facebook or watsapp, it stops giving location updates....
Hi...Anyone can help to get the someone mobile location through link or by hidden link?
Service stops after app is not in focus in my case :(
how long does the service take to stop in your case? I also encountered the same case. Do you know the cause and how to fix it?
Did u manage to resolve this issue>?
This may not work correctly when the app work in background. Simply not showing new updates, on the newest Android...
yeah, that's the problem, the code works, but in lower versions of 7, that's a problem that I found in my androrid 11, it doesn't work in foreground :c
I'm getting a delay=8000 ms and i don't know what to do I've searched online but couldn't get any help please help me out
can't get location updates after kill the app!!!
Nice code !!!!
Sorry sir, are Fused Location Provider APIs free to use?
Aren't they from Google Play Services? So Are Google Play Services APIs free to use?
Free
the code is not working in android 11v when app is running in background mode
thanks but how can i add it to a textview please
I appreciate your code but its too complicated for begineers
Sir please make a video on tablayout with only single fragment
But if you want only single fragment or screen then what is the meaning of tab layout since tab layout is used when you want to display multiple screens in single activity or something similar to that.
@@chiragkachhadiya sir you are right make Tablayout logic video
@@chiragkachhadiya please sir please sir
Here it is: th-cam.com/video/ajVVjuOSlV4/w-d-xo.html
Thank you for your reply sir this video is very helpful for me
Is it possible to jampack a volley method on the service class ?
Yes.
@@chiragkachhadiya It crashes the app when I put volley inside. Can you give me a hand please :(
Can you make a lap with aws ?
how would i call those latitude longitude values in another activity? any help would be appreciated
use broadcast reciever
@@anaslakhani hey can you help me how to set text for the value of lat and longt and keep updating it as the value be updated.
how to up location continuously to firebase
bro????
and background also
great tutorial sir. i've code your tutorial in kotlin, but when i click button stop location update, in my Log still get location update. is there any wrong?
Same as me bro
I'm not getting locations when the app is killed
Hey sir thank u for this video... Plz tell me how to save this latítude and longitude on database using postgreaql
sir i have issue how to show that lat and long in activity updated
Have you got, because I'm facing same problem.
how can we make it working in background please ?
Thankyou sir But not working not getting latlog
not working above api24 . kindly update what to do
Include access coarse location , access background location
SIR it doesn't work perfectly, plz help me...
How do we send result to MainActivity? Please someone help.
Using intent
broadcast receiver
Не хочет показывать координаты
bro source code ??
not working android 10
Fucking legend
give me aplication,please
Hey! Could I get the source code?
location updates are stopped, when the app is killed from background
you can't get location updates when the application stops, that's very normal
@@khalilsnoussi8559 I completely agree with you. But my requirement is getting location updates, even if the app is killed or background
@@chirujc i understood you, i had similar idea on my current project but in my case i needed notifications to show up even if the application wasnt working in the background and was very disappointed, actually notifications can't popup unless the actual application is working in the background you can test it with facebook or youtube apps.
@@khalilsnoussi8559 but I believe, there is a way. Working on that, I will update you, once I have working example.
@@khalilsnoussi8559 you can get location notifications, even if the app is killed from background . Here are the code changes to get it work
instead of calling
LocationServices.getFusedLocationProviderClient(this).requestLocationUpdates(locationRequest,locationCallback, Looper.getMainLooper());
startForeground(Constant.LOCATION_SERVICE_ID,builder.build());
use
LocationServices.getFusedLocationProviderClient(this).requestLocationUpdates(mLocationRequest, getPendingIntent());
and
private PendingIntent getPendingIntent() {
Intent intent = new Intent(this, LocationUpdatesIntentService.class);
intent.setAction(LocationUpdatesIntentService.ACTION_PROCESS_UPDATES);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
return PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
In service class
@Override
protected void onHandleIntent(Intent intent) {
if (intent != null) {
final String action = intent.getAction();
if (ACTION_PROCESS_UPDATES.equals(action)) {
LocationResult result = LocationResult.extractResult(intent);
if (result != null && result.getLocations()!=null) {
double latitude = result.getLastLocation().getLatitude();
double longitude =result.getLastLocation().getLongitude();
Log.d(TAG,"LOCATION UPDATE: "+latitude+" "+ longitude);
// sending data to popup notification, in my case, created static method sendNotification() in Utils class
Utils.sendNotification(this, ""+Utils.getLocationLatitude(this)+", "+Utils.getLocationLongitude(this) + ": " + DateFormat.getDateTimeInstance().format(new Date()));
}
}
}
}
In Utils class, add the following method
static void sendNotification(Context context, String notificationDetails) {
// Create an explicit content Intent that starts the main Activity.
Intent notificationIntent = new Intent(context, MainActivity.class);
notificationIntent.putExtra("from_notification", true);
// Construct a task stack.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
// Add the main Activity to the task stack as the parent.
stackBuilder.addParentStack(MainActivity.class);
// Push the content Intent onto the stack.
stackBuilder.addNextIntent(notificationIntent);
// Get a PendingIntent containing the entire back stack.
PendingIntent notificationPendingIntent =
stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
// Get a notification builder that's compatible with platform versions >= 4
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
// Define the notification settings.
builder.setSmallIcon(R.mipmap.ic_launcher)
// In a real app, you may want to use a library like Volley
// to decode the Bitmap.
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(),
R.mipmap.ic_launcher))
.setColor(Color.RED)
.setContentTitle("Location update")
.setContentText(notificationDetails)
.setContentIntent(notificationPendingIntent);
// Dismiss notification once the user touches it.
builder.setAutoCancel(true);
// Get an instance of the Notification manager
NotificationManager mNotificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
// Android O requires a Notification Channel.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = context.getString(R.string.app_name);
// Create the channel for the notification
NotificationChannel mChannel =
new NotificationChannel(CHANNEL_ID, name, NotificationManager.IMPORTANCE_HIGH);
// Set the Notification Channel for the Notification Manager.
mNotificationManager.createNotificationChannel(mChannel);
// Channel ID
builder.setChannelId(CHANNEL_ID);
}
// Issue the notification
mNotificationManager.notify(0, builder.build());
}
Source code please?
Error Android Q+
Source code
source code
Well, nice, but in 2020 Kotlin is the better choice....
i need the code bruhhhhhhhhh
Check instagram, DM you
Is it possible to download the code ?
if (service.foreground) //Always False
NotificationCompat.Builder //Dont show notifications
Background, dont work
This works great. Thank you so much