|
@@ -14,22 +14,29 @@ import android.util.Log;
|
|
public class MainActivity extends AppCompatActivity {
|
|
public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
final String TAG = "MainActivity";
|
|
final String TAG = "MainActivity";
|
|
|
|
+ Context appContx = null;
|
|
|
|
+ boolean locPermGranted = false;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
super.onCreate(savedInstanceState);
|
|
setContentView(R.layout.activity_main);
|
|
setContentView(R.layout.activity_main);
|
|
|
|
|
|
- Context appContx = getApplicationContext();
|
|
|
|
|
|
+ appContx = getApplicationContext();
|
|
|
|
|
|
final int hasPermission = ContextCompat.checkSelfPermission(appContx, Manifest.permission.ACCESS_FINE_LOCATION);
|
|
final int hasPermission = ContextCompat.checkSelfPermission(appContx, Manifest.permission.ACCESS_FINE_LOCATION);
|
|
- Log.i(TAG, "Permission: " + Integer.toString(hasPermission) );
|
|
|
|
|
|
+
|
|
if( hasPermission == PackageManager.PERMISSION_DENIED ) {
|
|
if( hasPermission == PackageManager.PERMISSION_DENIED ) {
|
|
Log.i(TAG, "Requesting permissions.....");
|
|
Log.i(TAG, "Requesting permissions.....");
|
|
locationPermissionRequest.launch(new String[]{
|
|
locationPermissionRequest.launch(new String[]{
|
|
- Manifest.permission.ACCESS_FINE_LOCATION
|
|
|
|
|
|
+ Manifest.permission.ACCESS_FINE_LOCATION,
|
|
|
|
+ Manifest.permission.ACCESS_COARSE_LOCATION
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
+ else {
|
|
|
|
+ Log.i(TAG, "Permissions already granted.");
|
|
|
|
+ locPermGranted = true;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
ActivityResultLauncher<String[]> locationPermissionRequest =
|
|
ActivityResultLauncher<String[]> locationPermissionRequest =
|
|
@@ -42,6 +49,7 @@ public class MainActivity extends AppCompatActivity {
|
|
if (fineLocationGranted != null && fineLocationGranted) {
|
|
if (fineLocationGranted != null && fineLocationGranted) {
|
|
// Precise location access granted.
|
|
// Precise location access granted.
|
|
Log.i(TAG,"Precise location granted");
|
|
Log.i(TAG,"Precise location granted");
|
|
|
|
+ locPermGranted = true;
|
|
} else if (coarseLocationGranted != null && coarseLocationGranted) {
|
|
} else if (coarseLocationGranted != null && coarseLocationGranted) {
|
|
// Only approximate location access granted.
|
|
// Only approximate location access granted.
|
|
Log.i(TAG,"approximate location granted");
|
|
Log.i(TAG,"approximate location granted");
|