-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyApp.java
46 lines (39 loc) · 1.48 KB
/
MyApp.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
43
44
45
46
package com.example.hugo.guitarledgend;
import android.app.Application;
import android.content.Intent;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import com.example.hugo.guitarledgend.bluetooth.BluetoothModule;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
public class MyApp extends Application {
private BluetoothModule mDevice;
public BluetoothModule getDevice() {
if (mDevice == null) {
// Defines a Handler object that's attached to the UI thread
Handler handler = new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(Message inputMessage) {
try {
byte[] shortenedMessage = Arrays.copyOf((byte[]) inputMessage.obj, inputMessage.arg1);
String value = new String(shortenedMessage, "UTF-8");
if (value.equals("1")) {
Intent intent = new Intent(BluetoothModule.ACTION_BATTERY_LOW);
sendBroadcast(intent);
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
};
try {
mDevice = new BluetoothModule(handler);
}
catch (Exception e) {
e.printStackTrace();
}
}
return mDevice;
}
}