From 65fc373f97066f563bad13025ddb117566c1b090 Mon Sep 17 00:00:00 2001 From: wiecktobi Date: Mon, 18 May 2020 21:52:52 +0200 Subject: [PATCH] Added permission request --- .../java/de/hft/geotracker/activities/Login.kt | 17 +++++++++++++++++ .../hft/geotracker/activities/MainActivity.kt | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/android/app/src/main/java/de/hft/geotracker/activities/Login.kt b/android/app/src/main/java/de/hft/geotracker/activities/Login.kt index 5de4b5b..9857068 100644 --- a/android/app/src/main/java/de/hft/geotracker/activities/Login.kt +++ b/android/app/src/main/java/de/hft/geotracker/activities/Login.kt @@ -1,11 +1,15 @@ package de.hft.geotracker.activities +import android.Manifest import android.content.Intent +import android.content.pm.PackageManager import android.os.Bundle import androidx.fragment.app.Fragment import android.widget.TextView import android.widget.Toast import androidx.appcompat.app.AppCompatActivity +import androidx.core.app.ActivityCompat +import androidx.core.content.ContextCompat import de.hft.geotracker.* import de.hft.geotracker.data.JWToken import de.hft.geotracker.retrofit.GeofenceService @@ -29,6 +33,19 @@ class Login : AppCompatActivity() { super.onCreate(savedInstanceState) setContentView(R.layout.activity_login) + if (ContextCompat.checkSelfPermission(this, + Manifest.permission.ACCESS_BACKGROUND_LOCATION + ) != PackageManager.PERMISSION_GRANTED) { + ActivityCompat.requestPermissions( + this, + arrayOf(Manifest.permission.ACCESS_BACKGROUND_LOCATION), + 1000 + ) + } else { + // Background location runtime permission already granted. + // You can now call geofencingClient.addGeofences(). + } + val retrofit = Retrofit.Builder() .baseUrl("http://plesk.icaotix.de:5000") .addConverterFactory(GsonConverterFactory.create()) diff --git a/android/app/src/main/java/de/hft/geotracker/activities/MainActivity.kt b/android/app/src/main/java/de/hft/geotracker/activities/MainActivity.kt index 902a9b9..2d89506 100644 --- a/android/app/src/main/java/de/hft/geotracker/activities/MainActivity.kt +++ b/android/app/src/main/java/de/hft/geotracker/activities/MainActivity.kt @@ -111,7 +111,7 @@ class MainActivity : AppCompatActivity() { } private fun getGeofencingRequest() : GeofencingRequest { return GeofencingRequest.Builder().apply { - setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_DWELL) + setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER) addGeofence(geofence) }.build() }