Exige le service de localisation pour faire fonctionner le scan
This commit is contained in:
parent
5e53e8fd85
commit
14c67e3abb
3 changed files with 46 additions and 24 deletions
|
@ -31,6 +31,9 @@
|
|||
<uses-feature
|
||||
android:name="android.hardware.bluetooth_le"
|
||||
android:required="true" />
|
||||
<uses-feature
|
||||
android:name=" android.hardware.location"
|
||||
android:required="true" />
|
||||
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
||||
|
|
|
@ -26,8 +26,10 @@ import android.bluetooth.BluetoothManager;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.location.LocationManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.provider.Settings;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -54,6 +56,7 @@ public class DeviceScanActivity extends ListActivity {
|
|||
|
||||
private static final int REQUEST_ENABLE_COARSE_LOCATION = 2;
|
||||
private static final int REQUEST_ENABLE_BT = 1;
|
||||
|
||||
// Stops scanning after 10 seconds.
|
||||
private static final long SCAN_PERIOD = 10000;
|
||||
|
||||
|
@ -145,13 +148,32 @@ public class DeviceScanActivity extends ListActivity {
|
|||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
// Vérifie si le service de localisation est actif sur l’appareil
|
||||
boolean location_enabled;
|
||||
try {
|
||||
location_enabled = Settings.Secure.LOCATION_MODE_OFF !=
|
||||
Settings.Secure.getInt(
|
||||
getContentResolver(),
|
||||
Settings.Secure.LOCATION_MODE
|
||||
);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
location_enabled = false;
|
||||
}
|
||||
|
||||
// Si le service de localisation n’est pas activé,
|
||||
// demande de l’activer dans les paramètres du système.
|
||||
if (!location_enabled) {
|
||||
Toast.makeText(this, "Prière d’activer une source de localisation.", Toast.LENGTH_LONG).show();
|
||||
Intent enableLocationIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
|
||||
startActivity(enableLocationIntent);
|
||||
}
|
||||
|
||||
// Ensures Bluetooth is enabled on the device. If Bluetooth is not currently enabled,
|
||||
// fire an intent to display a dialog asking the user to grant permission to enable it.
|
||||
if (!mBluetoothAdapter.isEnabled()) {
|
||||
if (!mBluetoothAdapter.isEnabled()) {
|
||||
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
|
||||
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
|
||||
}
|
||||
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
|
||||
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
|
||||
}
|
||||
|
||||
// Initializes list view adapter.
|
||||
|
@ -181,24 +203,12 @@ public class DeviceScanActivity extends ListActivity {
|
|||
protected void onListItemClick(ListView l, View v, int position, long id) {
|
||||
final BluetoothDevice device = mLeDeviceListAdapter.getDevice(position);
|
||||
if (device == null) return;
|
||||
if (false) {
|
||||
final Intent intent = new Intent(this, DeviceControlActivity.class);
|
||||
intent.putExtra(DeviceControlActivity.EXTRAS_DEVICE_NAME, device.getName());
|
||||
intent.putExtra(DeviceControlActivity.EXTRAS_DEVICE_ADDRESS, device.getAddress());
|
||||
if (mScanning) {
|
||||
mBluetoothAdapter.stopLeScan(mLeScanCallback);
|
||||
mScanning = false;
|
||||
}
|
||||
startActivity(intent);
|
||||
} else {
|
||||
final Intent intent = new Intent(this, SimpleDetailActivity.class);
|
||||
intent.putExtra(SimpleDetailActivity.EXTRAS_DEVICE_NAME, device.getName());
|
||||
intent.putExtra(SimpleDetailActivity.EXTRAS_DEVICE_ADDRESS, device.getAddress());
|
||||
if (mScanning) {
|
||||
mBluetoothAdapter.stopLeScan(mLeScanCallback);
|
||||
mScanning = false;
|
||||
}
|
||||
startActivity(intent);
|
||||
final Intent intent = new Intent(this, SimpleDetailActivity.class);
|
||||
intent.putExtra(SimpleDetailActivity.EXTRAS_DEVICE_NAME, device.getName());
|
||||
intent.putExtra(SimpleDetailActivity.EXTRAS_DEVICE_ADDRESS, device.getAddress());
|
||||
if (mScanning) {
|
||||
mBluetoothAdapter.stopLeScan(mLeScanCallback);
|
||||
mScanning = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
13
TODO.md
13
TODO.md
|
@ -3,15 +3,24 @@
|
|||
|
||||
Par ordre décroissant d’urgence :
|
||||
|
||||
- documentation du code Android ;
|
||||
- prise en charge de l’écriture des caractéristiques ;
|
||||
- ...
|
||||
- bouton « presse-papier »
|
||||
- bouton « partager » avec date, description etc.
|
||||
- historique ou graphe des mesures.
|
||||
|
||||
Fait
|
||||
-----
|
||||
Soutenance
|
||||
----------
|
||||
|
||||
- diapositives + présentation : 20'
|
||||
- démo
|
||||
|
||||
|
||||
Fait
|
||||
----
|
||||
|
||||
- vérification de l’activation de la localisation ;
|
||||
- affichage de la date de la dernière mesure ;
|
||||
- prise en charge des notifications des caractéristiques ;
|
||||
- filtrage des services et caractéristiques dans l’activité « DeviceControl » ;
|
||||
|
|
Loading…
Reference in a new issue