Skip to content

Commit

Permalink
BT enable request code
Browse files Browse the repository at this point in the history
  • Loading branch information
JorenSix committed Oct 1, 2015
1 parent f0ae392 commit 77e6c0b
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app/src/main/java/be/ugent/ipem/tgforcesensor/TgForceActivity.java
@@ -1,6 +1,10 @@
package be.ugent.ipem.tgforcesensor;

import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
Expand All @@ -27,6 +31,9 @@ protected void onCreate(Bundle savedInstanceState) {
textViewBattery = (TextView) findViewById(R.id.textViewBattery);
textViewStatus = (TextView) findViewById(R.id.textViewStatus);

//if BT is not enabled, request to enable it
requestBluetoothAccess();

sensor = new TgForceSensor(this.getApplicationContext(),this);


Expand Down Expand Up @@ -61,6 +68,16 @@ public boolean onOptionsItemSelected(MenuItem item) {
}


private static int REQUEST_ENABLE_BT = 56546;
private void requestBluetoothAccess(){
BluetoothManager btManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
BluetoothAdapter btAdapter = btManager.getAdapter();
if (btAdapter != null && !btAdapter.isEnabled()) {
Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
}
}


@Override
public void handleEvent(final TgForceEventType type, final double data) {
Expand Down

0 comments on commit 77e6c0b

Please sign in to comment.