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:
@@ -232,8 +232,10 @@ public class BluetoothPreferences extends PreferenceFragment {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceClick(Preference preference) {
|
public boolean onPreferenceClick(Preference preference) {
|
||||||
if (PermissionHelper.requestBluetoothPermission(getActivity(), fragment)) {
|
if (PermissionHelper.requestBluetoothPermission(getActivity(), fragment)) {
|
||||||
|
if (PermissionHelper.requestLocationServicePermission(getActivity())) {
|
||||||
startBluetoothDiscovery();
|
startBluetoothDiscovery();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@@ -18,6 +18,7 @@ package com.health.openscale.gui.utils;
|
|||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
|
import android.app.Dialog;
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.bluetooth.BluetoothManager;
|
import android.bluetooth.BluetoothManager;
|
||||||
@@ -25,11 +26,16 @@ import android.content.Context;
|
|||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import androidx.core.app.ActivityCompat;
|
import android.location.LocationManager;
|
||||||
|
import android.provider.Settings;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.health.openscale.R;
|
import com.health.openscale.R;
|
||||||
|
|
||||||
|
import androidx.core.app.ActivityCompat;
|
||||||
|
|
||||||
|
import static android.content.Context.LOCATION_SERVICE;
|
||||||
|
|
||||||
public class PermissionHelper {
|
public class PermissionHelper {
|
||||||
public final static int PERMISSIONS_REQUEST_ACCESS_COARSE_LOCATION = 1;
|
public final static int PERMISSIONS_REQUEST_ACCESS_COARSE_LOCATION = 1;
|
||||||
public final static int PERMISSIONS_REQUEST_ACCESS_READ_STORAGE = 2;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -193,6 +193,7 @@
|
|||||||
|
|
||||||
<string name="permission_not_granted">Permission not granted</string>
|
<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_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_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_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>
|
<string name="permission_read_write_data_label">Read/Write openScale Data</string>
|
||||||
|
Reference in New Issue
Block a user