This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun getLastKnownLocation( | |
onSuccess: ((lastKnownLocation: Location?) -> Unit)? = null, | |
onFail: ((exception: Exception) -> Unit)? = null | |
) { | |
val task: Task<Location> = mFusedLocationProviderClient.lastLocation | |
task.addOnSuccessListener { lastKnowLocation -> | |
if (lastKnowLocation == null) { | |
LogUtils.d("LocationKit -> Last Known Location is empty") | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun createLocationCallback( | |
onSuccess: ((location: Location?) -> Unit)? = null, | |
onFail: ((locationAvailability: LocationAvailability?) -> Unit)? = null | |
): LocationCallback { | |
return object : LocationCallback() { | |
override fun onLocationResult(locationResult: LocationResult) { | |
val currentLatLng = LatLng( | |
locationResult.lastLocation.latitude, | |
locationResult.lastLocation.longitude | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun registerLocationUpdates( | |
interval: Long = 10000, | |
onSuccess: ((location: Location?) -> Unit)? = null, | |
onFail: ((locationAvailability: LocationAvailability?) -> Unit)? = null | |
) { | |
val mLocationRequest = LocationRequest() | |
// Set the location update interval (in milliseconds). | |
mLocationRequest.interval = interval | |
// Set the weight. | |
mLocationRequest.priority = LocationRequest.PRIORITY_HIGH_ACCURACY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun unregisterLocationUpdates() { | |
mLocationCallback?.let { locationCallback -> | |
mFusedLocationProviderClient.removeLocationUpdates(locationCallback) | |
.addOnSuccessListener { | |
// Requesting location updates is stopped successfully. | |
LogUtils.d("LocationKit -> Stop Listening Location Successfully") | |
} | |
.addOnFailureListener { | |
// Failed to stop requesting location updates. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun checkLocationSettingsAndShowPopup( | |
activity: Activity, | |
onSuccess: ((locationSettingsResponse: LocationSettingsResponse?) -> Unit)? = null | |
) { | |
val builder = LocationSettingsRequest.Builder() | |
val locationRequest = LocationRequest() | |
builder.addLocationRequest(locationRequest) | |
val locationSettingsRequest = builder.build() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Wrapper class for handling Location related methods | |
*/ | |
class HuaweiLocationManager constructor(private val context : Context) { | |
//region vars | |
private val mFusedLocationProviderClient: FusedLocationProviderClient by lazy { | |
LocationServices.getFusedLocationProviderClient(context) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.P) { | |
Log.i(TAG, "sdk < 28 Q"); | |
if (ActivityCompat.checkSelfPermission(this, | |
Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED | |
|| ActivityCompat.checkSelfPermission(this, | |
Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { | |
String[] strings = | |
{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}; | |
ActivityCompat.requestPermissions(this, strings, 1); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { | |
super.onActivityResult(requestCode, resultCode, data) | |
if (requestCode == REQUEST_CHECK_SETTINGS) { | |
when (resultCode) { | |
Activity.RESULT_OK -> { | |
LogUtils.d("User confirm to access location") | |
} | |
Activity.RESULT_CANCELED -> { | |
LogUtils.d("User denied to access location") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Take photo from camera and save it to public gallery | |
// Before Q and After Q implementations | |
// Answer riginally taken from this SO answer | |
// https://stackoverflow.com/a/59482148/5695091 | |
private val REQUEST_TAKE_PHOTO = 101 | |
private val REQUEST_PICK_PHOTO = 102 | |
private var photoURI : Uri? = null | |
OlderNewer