Reenable our discovery activity for Android 6
Now that we request location we are allowed to do a btle scan again
This commit is contained in:
parent
7ef005f6a3
commit
88f338b0b9
|
@ -353,12 +353,8 @@ public class ControlCenter extends GBActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void launchDiscoveryActivity() {
|
private void launchDiscoveryActivity() {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
||||||
startActivity(new Intent(android.provider.Settings.ACTION_BLUETOOTH_SETTINGS));
|
|
||||||
} else {
|
|
||||||
startActivity(new Intent(this, DiscoveryActivity.class));
|
startActivity(new Intent(this, DiscoveryActivity.class));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package nodomain.freeyourgadget.gadgetbridge.activities;
|
package nodomain.freeyourgadget.gadgetbridge.activities;
|
||||||
|
|
||||||
|
import android.Manifest;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
|
@ -8,10 +9,12 @@ import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
|
import android.support.v4.app.ActivityCompat;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
@ -48,6 +51,7 @@ public class DiscoveryActivity extends GBActivity implements AdapterView.OnItemC
|
||||||
case BluetoothAdapter.ACTION_DISCOVERY_FINISHED:
|
case BluetoothAdapter.ACTION_DISCOVERY_FINISHED:
|
||||||
// continue with LE scan, if available
|
// continue with LE scan, if available
|
||||||
if (isScanning == Scanning.SCANNING_BT) {
|
if (isScanning == Scanning.SCANNING_BT) {
|
||||||
|
checkAndRequestLocationPermission();
|
||||||
startDiscovery(Scanning.SCANNING_BTLE);
|
startDiscovery(Scanning.SCANNING_BTLE);
|
||||||
} else {
|
} else {
|
||||||
discoveryFinished();
|
discoveryFinished();
|
||||||
|
@ -320,6 +324,12 @@ public class DiscoveryActivity extends GBActivity implements AdapterView.OnItemC
|
||||||
adapter.startDiscovery();
|
adapter.startDiscovery();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkAndRequestLocationPermission() {
|
||||||
|
if (ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||||
|
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Message getPostMessage(Runnable runnable) {
|
private Message getPostMessage(Runnable runnable) {
|
||||||
Message m = Message.obtain(handler, runnable);
|
Message m = Message.obtain(handler, runnable);
|
||||||
m.obj = runnable;
|
m.obj = runnable;
|
||||||
|
|
|
@ -129,11 +129,12 @@ public class SettingsActivity extends AbstractSettingsActivity {
|
||||||
pref = findPreference("location_aquire");
|
pref = findPreference("location_aquire");
|
||||||
pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||||
public boolean onPreferenceClick(Preference preference) {
|
public boolean onPreferenceClick(Preference preference) {
|
||||||
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
|
if (ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||||
Criteria criteria = new Criteria();
|
|
||||||
if (ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
|
||||||
ActivityCompat.requestPermissions(SettingsActivity.this, new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, 0);
|
ActivityCompat.requestPermissions(SettingsActivity.this, new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
|
||||||
|
Criteria criteria = new Criteria();
|
||||||
String provider = locationManager.getBestProvider(criteria, false);
|
String provider = locationManager.getBestProvider(criteria, false);
|
||||||
if (provider != null) {
|
if (provider != null) {
|
||||||
Location location = locationManager.getLastKnownLocation(provider);
|
Location location = locationManager.getLastKnownLocation(provider);
|
||||||
|
|
Loading…
Reference in New Issue