主要代碼實現:
public class BluetoolsPhoneUtil {
static String TAG = "BluetoolsPhoneUtil";
private static String filePath = "/sys/class/gpio_ctrl_class/gpio_ctrl_device/gpiopd28";
/**
* 操作Bluetooth
*/
public static void ctrlLedLight(String flag) {
try {
FileOutputStream outputStream = new FileOutputStream(filePath);
outputStream.write(flag.getBytes());
outputStream.flush();
outputStream.close();
} catch (Exception e) {
Log.d(TAG, "Exception:" + e.getMessage());
} finally {
}
}
/**
* 開機的時候打開Bluetooth
*/
public static void startLedLight() {
try {
ctrlLedLight("1");
Thread.sleep(5000);
ctrlLedLight("0");
} catch (Exception e) {
}
}
/**
* 接聽/掛斷電話改變Bluetooth狀態
*/
public static void changeLedLight() {
try {
ctrlLedLight("1");
Thread.sleep(200);
ctrlLedLight("0");
} catch (Exception e) {
}
}
}
其中調用startLedLight()方法,即可。