[Android分享] 通過藍牙,在兩臺設備之間傳遞音頻(包括音樂,通話)

通過藍牙,在兩臺設備之間傳遞音頻(包括音樂,通話)。

主要代碼實現:
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()方法,即可。

demo下載

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章