'getlastlocation returns null on android 29 or Higher. But I can get location Data on Lower version
I need to device location on android. I get this on Android 27 or lower. But when I checked on Android 29 or Higher, Its return null.
How can I do? Advanced Thanks.
private FusedLocationProviderClient client;
on code:
client = LocationServices.getFusedLocationProviderClient(getContext());
client.getLastLocation().addOnCompleteListener(new OnCompleteListener<Location>() {
@Override
public void onComplete(@NonNull Task<Location> task) {
Location location = task.getResult();
if (location != null){
double latitude = location.getLatitude();
double longitude = location.getLongitude();
latLng = new LatLng(latitude, longitude);
try {
String address = Common_Resources.getAttendanceAddress(getContext(), latitude, longitude);
check_In_Out_Dialog(type, address, latitude, longitude);
} catch (IOException e) {
e.printStackTrace();
Context context;
AlertDialog.Builder alert = new AlertDialog.Builder(getContext());
alert.setTitle("Please Enable your Location.");
alert.setNegativeButton("Close", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alert.show();
}
} else {
Log.e("Location: ", "onComplete: Location: "+ location);
}
}
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
