-
Notifications
You must be signed in to change notification settings - Fork 6
/
BTEnableControl.java
42 lines (35 loc) · 1.03 KB
/
BTEnableControl.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package dk.itu.android.btemu;
import dk.itu.android.bluetooth.BluetoothAdapter;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
public class BTEnableControl extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ctrl);
BluetoothAdapter.SetContext(this);
}
@Override
protected void onStart() {
super.onStart();
Intent started = getIntent();
Log.i("BTCTRL", "start with action: "+started.getAction());
if(started.getAction().equals(BluetoothAdapter.ACTION_REQUEST_ENABLE)) {
//start
BluetoothAdapter.getDefaultAdapter().enable();
setResult(RESULT_OK);
} else if(started.getAction().equals(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE)) {
//enabled discoverable
setResult(RESULT_OK);
}
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finish();
}
}