Using Telephonymanager To Get Location Throws Java.lang.securityexception
Hi in my app I am using TelephonyManager to get location. Here is the piece of code: TelephonyManager tm = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVI
Solution 1:
You must wait your permission checking process finished before calling tm.getCellLocation()
. Such as:
if (ContextCompat.checkSelfPermission(getApplicationContext(),
Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED ){
//do your request permission
}else{
// do your getLocation here
}
in your Activity
- onRequestPermissionsResult
, you can check is permission is granted or not then do getLocation
.
Post a Comment for "Using Telephonymanager To Get Location Throws Java.lang.securityexception"