1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-18 14:31:23 +02:00

request for location service is it not enabled to search for Bluetooth scales.

This commit is contained in:
oliexdev
2019-02-03 15:20:47 +01:00
parent bd8f1e4ccf
commit b8d1c4f47b
3 changed files with 39 additions and 3 deletions

View File

@@ -232,7 +232,9 @@ public class BluetoothPreferences extends PreferenceFragment {
@Override
public boolean onPreferenceClick(Preference preference) {
if (PermissionHelper.requestBluetoothPermission(getActivity(), fragment)) {
startBluetoothDiscovery();
if (PermissionHelper.requestLocationServicePermission(getActivity())) {
startBluetoothDiscovery();
}
}
return true;
}

View File

@@ -18,6 +18,7 @@ package com.health.openscale.gui.utils;
import android.Manifest;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.Fragment;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothManager;
@@ -25,11 +26,16 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import androidx.core.app.ActivityCompat;
import android.location.LocationManager;
import android.provider.Settings;
import android.widget.Toast;
import com.health.openscale.R;
import androidx.core.app.ActivityCompat;
import static android.content.Context.LOCATION_SERVICE;
public class PermissionHelper {
public final static int PERMISSIONS_REQUEST_ACCESS_COARSE_LOCATION = 1;
public final static int PERMISSIONS_REQUEST_ACCESS_READ_STORAGE = 2;
@@ -70,7 +76,34 @@ public class PermissionHelper {
}
});
builder.show();
Dialog alertDialog = builder.create();
alertDialog.setCanceledOnTouchOutside(false);
alertDialog.show();
return false;
}
return true;
}
public static boolean requestLocationServicePermission(final Activity activity) {
LocationManager locationManager = (LocationManager) activity.getSystemService(LOCATION_SERVICE);
if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(R.string.permission_bluetooth_info_title);
builder.setIcon(R.drawable.ic_preferences_about);
builder.setMessage(R.string.permission_location_service_info);
builder.setPositiveButton(R.string.label_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int i) {
// Show location settings when the user acknowledges the alert dialog
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
activity.startActivity(intent);
}
});
Dialog alertDialog = builder.create();
alertDialog.setCanceledOnTouchOutside(false);
alertDialog.show();
return false;
}

View File

@@ -193,6 +193,7 @@
<string name="permission_not_granted">Permission not granted</string>
<string name="permission_bluetooth_info">Coarse location permission needed to search for Bluetooth devices. It can be revoked after the device is found.</string>
<string name="permission_location_service_info">Location Service (GPS) needs to be enabled to search for Bluetooth scale. Please enable it under Android settings.</string>
<string name="permission_bluetooth_info_title">Info</string>
<string name="permission_read_write_data_description">read/write openScale data, including user information and all saved measurements</string>
<string name="permission_read_write_data_label">Read/Write openScale Data</string>