Giter Club home page Giter Club logo

birjuvachhani / locus-android Goto Github PK

View Code? Open in Web Editor NEW
343.0 343.0 41.0 1.21 MB

An Awesome Kotlin Location library to retrieve location merely in 3 lines of code

Home Page: https://birju.dev/posts/retrieve-location-in-just-3-lines-android/

License: Apache License 2.0

Kotlin 100.00%
android android-development android-library android-location android-permission android-studio fusedlocationproviderclient hacktoberfest hacktoberfest-accepted hacktoberfest2023 kotlin-android kotlin-android-extensions kotlin-dsl kotlin-extensions kotlin-language location

locus-android's Introduction

banner

Locus-Android

License language Platform API Release

Locus is a tiny kotlin library for android which makes it super very easy to retrieve location with just few lines of code. Everything including permission model and Location settings resolution is handled internally which removes a lot of boilerplate code any developer have to write every time.

Looking for Maintainers

Its been a long time since I moved away from native Android development so I am finding it hard to keep up with the latest changes with the location permissions in newever Android versions and fix issues reported here. I'd love someone to actively maintain this library and look into the issues. If you are interested and up to the task, drop a mail at [email protected] or comment on this issue. Thanks!

Documentation:

See Wiki for more information and configuration!

Read blog here:

Features

  • Android R support (Please report if any issue is found)
  • Completely written in Kotlin
  • Easy Initialization
  • Handles Permission Model
  • No Boilerplate
  • Built on Kotlin DSL
  • Manifest Permission Check
  • Life-Cycle Aware Location Updates
  • Location Settings Check
  • Location Settings Request
  • Custom Location Options Configuration
  • Custom Rationale Dialog configuration
  • Custom Permission Blocked Dialog configuration

IMPORTANT:

Breaking Changes from v4.0.0

Text Customizations using Locus.configure{} block which were deprecated in v3.2.0 have been now removed completely. This means rationaleText, rationaleTitle, blockedTitle, blockedText, resolutionTitle, and resolutionText no longer exist on Locus.configure{}. Migration would be to customize/override them from strings.xml.

Before

Locus.configure {
    rationaleTitle = "Rationale Title"
    rationaleTitle = "This is a rationale message."
    blockedTitle = "Permission Blocked Title"
    blockedText = "This is a permission blocked message."
    resolutionTitle = "Permission Resolution Title"
    resolutionText = "This is a permission resolution message."
}

Now

strings.xml

<string name="locus_rationale_title">Rationale Title</string>
<string name="locus_rationale_message">This is a rationale message.</string>
<string name="locus_permission_blocked_title">Permission Blocked Title</string>
<string name="locus_permission_blocked_message">This is a permission blocked message.</string>
<string name="locus_location_resolution_title">Permission Resolution Title</string>
<string name="locus_location_resolution_message">This is a permission resolution message.</string>
<string name="grant">Grant</string>
<string name="deny">Deny</string>

checkout strings.xml.

How to disable background location permission if you don't use it.

It has been brought to my attention recently that this library includes background location permission in its AndroidManifest.xml file. This could cause a problem when publishing app on Google Play Store in a case where your does not actually request or use background location. If that happens then this is what you need to do.

Just add this line in your app's AndroidManifest.xml file and you should be good to go.

<uses-permission tools:node="remove" android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />

Feel free to re-open #53 issue or file a new one if this does not work for you.

Gradle Dependency

  1. Add the JitPack repository.

For Classic Android Project:

Add this in your project's build.gradle file.

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' } // add this line only
    }
}

For Compose Android Project:

Add this in your project's settings.gradle file.

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        ...
        maven { url 'https://jitpack.io' } // add this line only
    }
}
  1. Add the dependency in your app's build.gradle file

Release

dependencies {
    implementation 'com.github.BirjuVachhani:locus-android:latest-version'
    implementation 'com.google.android.gms:play-services-location:latest-version'
}

Usage

See Wiki on how to get started with Locus.

Background Location Permission Removal

This package adds background location permission to the manifest file regardless whether you are using it or not. If you are not requesting background location permission and you are not planning to use it in future, consider adding this line into your manifest file. This is only required when you publish your app to Google Playstore because they might reject your app because of this. See realted issue #53.

<uses-permission tools:node="remove" android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />

Pull Request

To generate a pull request, please consider following Pull Request Template.

Issues

To submit an issue, please check the Issue Template.

Code of Conduct

Code of Conduct

Contribution

You are most welcome to contribute to this project!

Please have a look at Contributing Guidelines, before contributing and proposing a change.

Buy Me A Coffee

License

   Copyright © 2019 BirjuVachhani

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

locus-android's People

Contributors

abdullqadir avatar amir-p avatar birjuvachhani avatar iballan avatar kosratdev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

locus-android's Issues

Displaying permission settings dialog continuously when location permission is not added in manifest

@BirjuVachhani
I am using this lib in my app, and just came across with one found issue. If I haven't declare Location permission in manifest ( which is require for lib) the lib will display settings dialog for permission continuously. Can you please check and resolved it.

Thanks you for the wonderful lib.
Steps To reproduce:
-> Try to run access location using your lib without adding location permission in app manifest.

Getting Location without GMS and HMS.

Is your feature request related to a problem? Please describe.
The library supports both GMS and HMS what if we have a device that doesn't have both of them?

Describe the solution you'd like
To support Android devices that lack Google Mobile Services (GMS) and Huawei Mobile Services (HMS), we can use alternative Android APIs that do not require either platform to obtain the user's current location.

Describe alternatives you've considered
None.

Additional context
None.

Accurate current Location is invalid

Describe the bug
The library doesn't support to get user current location and it's depend on google map location to retrieve the last known location, please can you solve it
@BirjuVachhani

To Reproduce
Steps to reproduce the behavior:
1- open app
2- request to get current location (Locus.getCurrentLocation())

Expected behavior
I expected to retrieve the user current location instead of the last known location

Smartphone (please complete the following information):

  • Any version

Crashes in get location on all fragments with use of base fragment.

Prerequisites

Description

When we trying to use locus lib in viewpager with different fragments it gives me crashes and below is the debug log.

java.lang.IllegalStateException: Fragment LocationHelper{40f9948 (a28e8a4f-2db1-4ee2-8840-5546503ef983) LocationHelper} not attached to an activity.
        at androidx.fragment.app.Fragment.requireActivity(Fragment.java:716)
        at com.birjuvachhani.locationextension.LocationHelper.hasLocationPermission(LocationHelper.kt:182)
        at com.birjuvachhani.locationextension.LocationHelper.initPermissionModel(LocationHelper.kt:128)
        at com.birjuvachhani.locationextension.Locus.initLocationHelper(Locus.kt:150)
        at com.birjuvachhani.locationextension.Locus.getCurrentLocation(Locus.kt:94)
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:896)
        at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManagerImpl.java:1229)
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1295)
        at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:686)
        at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManagerImpl.java:2057)
        at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManagerImpl.java:1847)
        at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManagerImpl.java:1802)
        at androidx.fragment.app.FragmentManagerImpl.execSingleAction(FragmentManagerImpl.java:1679)
        at androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:536)
        at androidx.fragment.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:170)
        at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1244)
        at androidx.viewpager.widget.ViewPager.setCurrentItemInternal(ViewPager.java:669)
        at androidx.viewpager.widget.ViewPager.setCurrentItemInternal(ViewPager.java:631)
        at androidx.viewpager.widget.ViewPager.setCurrentItem(ViewPager.java:612)
        at com.google.android.material.tabs.TabLayout$ViewPagerOnTabSelectedListener.onTabSelected(TabLayout.java:2831)
        at com.google.android.material.tabs.TabLayout.dispatchTabSelected(TabLayout.java:1608)
        at com.google.android.material.tabs.TabLayout.selectTab(TabLayout.java:1601)
        at com.google.android.material.tabs.TabLayout.selectTab(TabLayout.java:1569)
        at com.google.android.material.tabs.TabLayout$Tab.select(TabLayout.java:1874)
        at com.google.android.material.tabs.TabLayout$TabView.performClick(TabLayout.java:2059)
        at android.view.View.performClickInternal(View.java:6574)
        at android.view.View.access$3100(View.java:778)
        at android.view.View$PerformClick.run(View.java:25885)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

Steps to Reproduce

  1. Initializing locus object on each fragment inside viewpager.
  2. It crashes when the page offset limit of viewpager is default and total fragments are greater then that.

Expected behavior: It should not be crash.

Actual behavior: It crashes.

Reproduces how often: Every time when viewpager screen navigate.

Additional Information

Any additional information, configuration or data that might be necessary to reproduce the issue.

Failed to resolve dependency

  > Could not find locus-android-4.1.0.aar (com.github.BirjuVachhani:locus-android:4.1.0).
        Searched in the following locations:
            https://jitpack.io/com/github/BirjuVachhani/locus-android/4.1.0/locus-android-4.1.0.aar

Errors in locat Pending Intent

java.lang.IllegalArgumentException: com.taskflo: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
    at android.app.PendingIntent.checkFlags(PendingIntent.java:375)
    at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:651)
    at android.app.PendingIntent.getBroadcast(PendingIntent.java:638)
    at com.birjuvachhani.locus.LocationBroadcastReceiver$Companion.getPendingIntent(LocationBroadcastReceiver.kt:41)
    at com.birjuvachhani.locus.LocationProvider$pendingIntent$2.invoke(LocationProvider.kt:40)
    at com.birjuvachhani.locus.LocationProvider$pendingIntent$2.invoke(LocationProvider.kt:37)
    at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)

Dialog while request background location

Is your feature request related to a problem? Please describe.
No

Describe the solution you'd like
Show the popup before requesting for background location service all the time. It's better to have alert dialog with new string fields for the message.

Describe alternatives you've considered
Changed the location request message to reflect the changes.

Additional context
You can find the full screenshots at: https://imgur.com/a/L7fClCO

Require functionality of change message text for update rational and permanently deny permissions.

Prerequisites

Description

Required access to change message of change message text for update rational and permanently deny permissions.

Steps to Reproduce

  1. Request permission and press deny button on permission dialog.
  2. It will show dialog and required feature to change dialog text.

Expected behavior: Message text change.

Actual behavior: Message text not changing.

Reproduces how often: Request permission and press deny button on permission dialog.

Additional Information

Any additional information, configuration or data that might be necessary to reproduce the issue.

Looking for Maintainers

Hi all,

Thank you for using this library and showing your support and interest for this library. Its been a long time since I moved away from native Android development and I am finding it hard to keep up with the latest changes with the location permissions in newer Android versions and fix issues reported here. I'd love someone to actively maintain this library and look into the issues. I am looking for maintainers who have detailed experience around Android location permission model and can keep this library up to date with changes made in Android.

If you are interested and up for the task, drop a comment here.

Thanks.

Location SingleUpdate sometimes not accurate

Describe the bug
Locus's single location update is not accurate, sometimes. I need help trying to figure this out.

To Reproduce
Steps to reproduce the behavior:

  1. Create app with Locus
  2. Use the below config:
        Locus.configure {
            enableBackgroundUpdates = true
            forceBackgroundUpdates = true
        }
  1. Ask for location using:
                Locus.getCurrentLocation(context) { result ->
                    result.location?.let {
                        /* Received location update */

Expected behavior
Always get the correct latitude / longitude, give or take 20 meters.

Screenshots
not applicable

Desktop (please complete the following information):

  • OS: Windows
  • Android Studio: Hedgehog | 2023.1.1 Beta 1
  • Locus: 4.1.2

Smartphone (please complete the following information):

  • Device: Samsung Galaxy S21 FE

Additional context
I am trying to understand if I am not using the library correctly, or if this is a limitation of the underlying FusedLocationProvider.
I don't want to conserve battery, I want the best/highest accuracy location the phone can give me. It's only happening 2-3 times per day. Is there any way to force it to provide better location?

Also, I don't know how to debug this. Can you help me check if this is Locus bug or GMS bug?

I have a foreground service, how to Locus in that service

I want to use locus in my foreground Service.
Hello, I want to access location when my application is in background for this i have created a foreground service in my app, but im unable to use locus in foreground service as it is asking for instance of fragment,
Kindly give me some sample code that how can i use this library if foreground service ?

Support for Coarse/Approximate Location Only

Describe the bug
I have an app that can work with coarse/approximate location. when the user chooses to use approximate location from the permission request dialog the Locus location request seem to detect that the permission has not been granted. I think its because Locus uses fine/percise location only.

To Reproduce
Steps to reproduce the behavior:

  1. Request location and allow approximate location only
  2. Invoke Locus for a location request
  3. LocusRequest produces an error of permission denied and no location data is provided.

Expected behavior
Proceed to provide the location according to the restrictions of approximate location use.

Smartphone (please complete the following information):

  • Device: Xiaomi 11T
  • OS: Android 13
  • Version 5.0.0

location_settings_denied returned while enabling the location.

Describe the bug
When the device's location is turned off then the app requests to enable location after you enable it, it will return location_settings_denied

To Reproduce
Steps to reproduce the behavior:

  1. Turn off your locatoin.
  2. Go to your app that uses this library.
  3. Request to get Locus.getCurrentLocation
  4. Enable location
  5. See error

Expected behavior
After enabling the location should retry to get the location instead returning location_settings_denied

Smartphone (please complete the following information):

  • Device: Samsung A70
  • OS: Android
  • Version: Android 11

if location disabled in settings it ask to enable location in settings but can't get location after enable it.

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Crashes when tries to go for location settings

Device: Poco F3
OS: Android 12

java.lang.IncompatibleClassChangeError: Found interface com.google.android.gms.location.SettingsClient, but class was expected (declaration of 'com.google.android.gms.location.SettingsClient' appears in /data/app/~~Yu4lRTFSjrQeAB3dMXGmIg==/com.example.app-jK1oINC_g1INHcHHe6qjKA==/base.apk)
                                                                                                    	at com.birjuvachhani.locus.LocusActivity.checkSettings(LocusActivity.kt:273)
                                                                                                    	at com.birjuvachhani.locus.LocusActivity.checkIfLocationSettingsAreEnabled(LocusActivity.kt:243)
                                                                                                    	at com.birjuvachhani.locus.LocusActivity.onPermissionGranted(LocusActivity.kt:178)
                                                                                                    	at com.birjuvachhani.locus.LocusActivity.onRequestPermissionsResult(LocusActivity.kt:165)
                                                                                                    	at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:8794)
                                                                                                    	at android.app.Activity.dispatchActivityResult(Activity.java:8647)
                                                                                                    	at android.app.ActivityThread.deliverResults(ActivityThread.java:5415)
                                                                                                    	at android.app.ActivityThread.handleSendResult(ActivityThread.java:5461)
                                                                                                    	at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:54)
                                                                                                    	at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
                                                                                                    	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
                                                                                                    	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
                                                                                                    	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2259)
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:106)
                                                                                                    	at android.os.Looper.loopOnce(Looper.java:210)
                                                                                                    	at android.os.Looper.loop(Looper.java:299)
                                                                                                    	at android.app.ActivityThread.main(ActivityThread.java:8105)
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method)
                                                                                                    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:556)
                                                                                                    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1045)

Above is the crash log. Below is the code is used

 Locus.startLocationUpdates(this) { result ->
            result.location?.let {//Recieved location  }
            result.error?.let { /* Received error! */ }
        }

Move dialog texts from configuration to string.xml

Is your feature request related to a problem? Please describe.
Improve text messages in the dialogs to be easily translatable without any efforts.

Describe the solution you'd like
Move the text messages in the configuration to string.xml file and then anyone can override and translate them easily just by adding the text keys to their strings.xml files.

Custom dialog designs.

Is your feature request related to a problem? Please describe.
The existing dialogs suffer from being incompatible with some designs like Material 3. and not being able to change colors, fonts, etc.

Describe the solution you'd like
it would be helpful if the dialogs design could be customized or disabled and replaced with a custom implementation.

Describe alternatives you've considered
Handle location permission check dialogs before calling Locus for location.

Additional context
None.

Changing the style of dialogs and disabling them.

Is it possible to customize the styling of the dialogs ?
I have a problem with the settings resolution dialog, the buttons are displayed in red.

also is it possible to disable the settings resolution dialog ? because it's unnecessary as Google already shows one so it would be awesome if you provide an option to either show it or not

On-Click of Deny button Dismiss Permission Alert

Permission
Currently, OnClick of Deny, It is asking/showing again and again.

Solution
OnClick of Deny, the Permission Dialog should be dismissed.

Alternative
Not a good approach, Surrounded it with Dexter permission handling

Background permission getting added in the merged manifest

Describe the bug
I loved locus, the implementation was really easy and it handles everything but the only issue is that I do not need background location updates, i only need it on demand, but after implementing locus Background permission is getting added to the merged manifest as well and so i have an issue in uploading it on the play store.

To Reproduce
Steps to reproduce the behavior:

  1. Import locus
  2. Check merged manifest
    Expected behavior

As mentioned i require the location only on demand, so is it possible to get only that and not have to take the background location permission?

Thanks in advance!
Screenshot 2021-09-27 at 1 24 24 PM
ce

Location Issuse

Location not provided when enabling location button

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Crash with Failed resolution of: Lcom/google/android/gms/location/LocationRequest

Prerequisites

Description

Crash on some phones like: Honor Play [Android 9 OS].

Steps to Reproduce

  1. Start Locus.getCurrentLocation in app
  2. Crash with java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/location/LocationRequest;
  3. Always crashes

Expected behavior: [What you expect to happen]
Should not crash and handle or uses the latest API

Actual behavior: [What actually happens]
Crash everytime

Reproduces how often: [What percentage of the time does it reproduce?]
Always

Additional Information

Crash Log:
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/location/LocationRequest; at com.birjuvachhani.locus.ConfigurationKt.getDefaultRequest(Configuration.kt:68) at com.birjuvachhani.locus.Configuration.<init>(Configuration.kt:41) at com.birjuvachhani.locus.Locus.<clinit>(Locus.kt:84) at com.openapp.tusk.ui.base.BaseFragment.onDestroyView(BaseFragment.kt:106) at com.openapp.tusk.ui.view.main.SplashFragment.onDestroyView(Unknown Source:0) at androidx.fragment.app.Fragment.performDestroyView(Fragment.java:2908) at androidx.fragment.app.FragmentManager.destroyFragmentView(FragmentManager.java:1344) at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1264) at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1356) at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1434) at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1504) at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2007) at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1953) at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1849) at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:2629) at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:2577) at androidx.fragment.app.Fragment.performActivityCreated(Fragment.java:2722) at androidx.fragment.app.FragmentStateManager.activityCreated(FragmentStateManager.java:346) at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1188) at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1356) at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1434) at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1497) at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:2625) at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:2577) at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:247) at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:541) at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:201) at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1419) at android.app.Activity.performStart(Activity.java:7479) at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3454) at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:180) at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:165) at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:142) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2199) at android.os.Handler.dispatchMessage(Handler.java:112) at android.os.Looper.loop(Looper.java:216) at android.app.ActivityThread.main(ActivityThread.java:7625) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987) Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.location.LocationRequest" on path: DexPathList[[zip file "/data/app/com.openapp.tusk.beta-mADMueluT9dYZT2i1eUpzg==/base.apk"],nativeLibraryDirectories=[/data/app/com.openapp.tusk.beta-mADMueluT9dYZT2i1eUpzg==/lib/arm64, /data/app/com.openapp.tusk.beta-mADMueluT9dYZT2i1eUpzg==/base.apk!/lib/arm64-v8a, /system/lib64, /product/lib64]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134) 2020-03-04 12:40:10.159 5240-5240/com.openapp.tusk.beta E/AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:379) at java.lang.ClassLoader.loadClass(ClassLoader.java:312) ... 41 more

Handle Error itself

Hello devs, loved the lib, everything is alright
Only thing i want to know how to use Locus inbuilt error dialogs instead of writing own implementation in result.error block

Request enable location crash

Describe the bug
The second request to enable location will make a crash if the first has been canceled.

To Reproduce
Steps to reproduce the behavior:

  1. Go to device settings and turn off the location.
  2. Open the locus sample app.
  3. Enable resolve location settings.
  4. Start getting location
  5. The app asks to enable location service.
  6. Cancel the request
  7. Press the start button again
  8. Crash 💥

Expected behavior
I'm expecting to request to enable the location again.

Screenshots
Screenshot 2023-05-18 at 16 03 03

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: Emulator
  • OS: Android API 33
  • Browser [e.g. stock browser, safari]
  • Version 4.1.1

Additional context
Add any other context about the problem here.

Update Documentation for LocationRequest Configuration (Release v4.1.1)

I recently updated to Release v4.1.1 and encountered some deprecated functions within the location request configuration. The new recommended approach in this release is to use the LocationRequest.Builder for location request configuration.
I guess the docs are not updated yet, can you provide an example on how to use it?

Deprecated code snippet:

Locus.configure {
    request {
        fastestInterval = 1000
        priority = LocationRequest.PRIORITY_HIGH_ACCURACY
        interval = 1000
        maxWaitTime = 2000
    }
}

Support Huawei HMS Location Kit

Is your feature request related to a problem? Please describe.
As you know, Google Play Service has been banned in Huawei devices since 2019. After that, Huawei created its own library to provide location services. It could be a great feature if there is a library to support both services at the same time.

Describe the solution you'd like
Support Google Play Service and Huawei HMS Location in the same library.

Describe alternatives you've considered

Additional context

MavenCentral migration

Will this library be moved to MavenCentral soon since Jitpack is no longer available?

Thanks.

Android Api 30 get current location

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Start android API 30
  2. call getCurrentLocation
  3. Current location is null

Expected behavior
For some reason, the same piece of code works for Android 33 but doesn't work for 30...
Trying to use getCurrentLocation

Screenshots
SCR-20221024-n9f
SCR-20221024-n8y

Pending intents need to have either FLAG_IMMUTABLE or FLAG_MUTABLE

When trying to run my app on an API 31 emulator, I get a crash with the following stack track:

java.lang.IllegalArgumentException: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
at android.app.PendingIntent.checkFlags(PendingIntent.java:375)
at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:645)
at android.app.PendingIntent.getBroadcast(PendingIntent.java:632)
at com.birjuvachhani.locus.LocationBroadcastReceiver$Companion.getPendingIntent(LocationBroadcastReceiver.kt:41)
at com.birjuvachhani.locus.LocationProvider$pendingIntent$2.invoke(LocationProvider.kt:40)
at com.birjuvachhani.locus.LocationProvider$pendingIntent$2.invoke(LocationProvider.kt:39)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
at com.birjuvachhani.locus.LocationProvider.getPendingIntent(LocationProvider.kt:39)
at com.birjuvachhani.locus.LocationProvider.startUpdates$locus_release(LocationProvider.kt:56)
at com.birjuvachhani.locus.Locus.startUpdates(Locus.kt:248)
at com.birjuvachhani.locus.Locus.access$startUpdates(Locus.kt:81)
at com.birjuvachhani.locus.Locus$checkAndStartLocationUpdates$2.invoke(Locus.kt:209)
at com.birjuvachhani.locus.Locus$checkAndStartLocationUpdates$2.invoke(Locus.kt:206)
at com.birjuvachhani.locus.Locus.checkLocationSettings$lambda-3(Locus.kt:233)
at com.birjuvachhani.locus.Locus.$r8$lambda$9D3IJ2F1aenyoyH999DecV6GSsU(Unknown Source:0)
at com.birjuvachhani.locus.Locus$$ExternalSyntheticLambda3.onSuccess(Unknown Source:4)
at com.google.android.gms.tasks.zzn.run(com.google.android.gms:play-services-tasks@@17.2.0:4)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7839)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)

Not Working in android 6

I am not getting lcation in android 6.0 everything is working fine above android 6.0 please take a look

// using this

Locus.getCurrentLocation(this) { result ->
if (result.location != null) {

        } else {
            
        }
        Print.P("Inside listener") 
    }

Cannot get latest location from fun getCurrentLocation(context: Context,onResult: (LocusResult) -> Unit)

the API doesnt support for threadings from androidx.work, we tried async{}, runBlocking{} but it doest help, the API runs async in the underlying thread
Cannot get latest location from fun getCurrentLocation(context: Context,onResult: (LocusResult) -> Unit)

class MyWorker(mContext: Context, workerParameters: WorkerParameters) :
    Worker(mContext, workerParameters) {
  override fun doWork(): Result {
Locus.getCurrentLocation(applicationContext) { result ->
                    result.location!!.let {
//none of values retrived
}
}
  }
}

Please help support API return in future/promises

Not receiving location updates while screen is off

Describe the bug
Hi, i use your library in a foreground service, when device is unlocked it gets location updates, but when device is locked it doesn't get location update, can you please help me with this?

Expected behavior
should receive location updates when device is locked.

Smartphone (please complete the following information):

  • Device: Xiaomi Redmi Note 9 Pro
  • OS: Android
  • Version 10

Some help needed

Thanks for the great library.

My questions are:

1- How to get location if internet (wifi / mobile data) is off, GPS only?
2- If GPS is off how can we turn on location programmatically? Can you put this feature in your library?

Thank you once again for this library.

Github Action not working with Locus

Thank you for your library, however there is some problem in integrating with Github Action :

Describe the bug
Cannot Implement locus with Github Action

To Reproduce
Run build build android in github action with locus implemented

Expected behavior
the build is successful

Screenshots
image

Unable to get current location

Bug
App crashes when initializing Locus for getting current location in a fragment

To Reproduce
Steps to reproduce the behavior:

  1. Initialize locus to get current location
 Locus.getCurrentLocation(requireContext()) { locusResult: LocusResult ->
    // Your task
}
  1. Open the fragment that gets the current location using above api
  2. App crashes

Expected behavior
Get current location

Device info:

  • Device: Lenovo K10 Note
  • OS: Android
  • Version: Pie (API 28)

Additional context
Here's the error:

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/location/LocationRequest;
        at com.birjuvachhani.locus.ConfigurationKt.getDefaultRequest(Configuration.kt:68)
        at com.birjuvachhani.locus.Configuration.<init>(Configuration.kt:41)
        at com.birjuvachhani.locus.Locus.<clinit>(Locus.kt:84)

Last few lines:

Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.location.LocationRequest" on path: DexPathList[[zip file "/data/app/ai.microfinance.lyt-d39yxfzmfFCl5laJw1nNXg==/base.apk"],nativeLibraryDirectories=[/data/app/ai.microfinance.lyt-d39yxfzmfFCl5laJw1nNXg==/lib/arm64, /system/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)

Don't build with jetpack compose

Describe the bug
Jetpack compose app dont'build with Locus.
Errors:
AAPT: error: style attribute 'attr/colorAccent (aka com.example.testapplication:attr/colorAccent)' not found.
AAPT: error: style attribute 'attr/colorPrimary (aka com.example.testapplication:attr/colorPrimary)' not found.
AAPT: error: style attribute 'attr/colorPrimaryDark (aka com.example.testapplication:attr/colorPrimaryDark)' not found.

To Reproduce
Steps to reproduce the behavior:
1- Create empty compose app
2- Configure use of Locus
3- Try to build

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.