Skip to content

Commit

Permalink
NEW FEATURE: actively ask for location permission
Browse files Browse the repository at this point in the history
  • Loading branch information
NeutrinoLiu committed Jan 8, 2022
1 parent f1dce7b commit 31b04ac
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/src/main/java/com/example/decentspec_v3/GPSTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ public GPSTracker(Context context) {
List<String> providerList = mLocationManager.getProviders(true);
if (! providerList.contains(LocationManager.GPS_PROVIDER))
avail = false;
else if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED)
else if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
avail = false;
}
else
avail = true;
}
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/com/example/decentspec_v3/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.example.decentspec_v3;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ActivityManager;
Expand Down Expand Up @@ -227,6 +229,9 @@ public void toggleSerialService(View view) {
}
/*start foreground service*/
Intent runMyService = new Intent(this, SerialListenerService.class);
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_BACKGROUND_LOCATION},
10);
runMyService.setAction(START_ACTION);
startForegroundService(runMyService);
serial_switch.setChecked(ifMyServiceRunning(SerialListenerService.class));
Expand Down

0 comments on commit 31b04ac

Please # to comment.