メインアクティビティとクラスを持つアプリがあります。戻るボタンを押すと、アプリは閉じるはずですが、何もしません。ボタンを押すと、ボタンのバックライトがオンになり、オフになります。もう一度押すと、音のフィードバックが聞こえます。
私のアプリは常に Bluetooth 通信を行っています。Bluetooth はキーの通常の動作を上書きできますか?
onPause と onResume もあります。
onBackPressed で試してみましたが、呼び出されません:
@Override
public void onBackPressed() {
super.onBackPressed();
Log.i ("INFO","BackKey pressed");
}
BtComm クラス:
//Enables Bluetooth if not enabled
public void enableBT(){
localAdapter=BluetoothAdapter.getDefaultAdapter();
//If Bluetooth not enable then do it
if(localAdapter.isEnabled()==false){
localAdapter.enable();
while(!(localAdapter.isEnabled())){
}
}
}
//connect to both NXTs
public boolean connectToNXTs(){
//get the BluetoothDevice of the NXT
BluetoothDevice nxt_1 = localAdapter.getRemoteDevice(nxt1);
//try to connect to the nxt
try {
socket_nxt1 = nxt_1.createRfcommSocketToServiceRecord(UUID
.fromString("00001101-0000-1000-8000-00805F9B34FB"));
socket_nxt1.connect();
success = true;
} catch (IOException e) {
Log.i("Bluetooth","Err: Device not found or cannot connect");
success=false;
}
if (success) {
Log.i("CONECTE","CONEXION EXITOSA");
}
return success;
}
public void writeMessage(byte[] msg) throws InterruptedException{
//BluetoothSocket connSock;
// connSock=socket_nxt1;
try {
// OutputStreamWriter out =new OutputStreamWriter(connSock.getOutputStream());
// mmOutStream.write(msg);
// out.flush();
OutputStream outputStream = socket_nxt1.getOutputStream();
outputStream.write(msg);
Log.i("Excelente","COMANDO EXITOSO");
} catch (IOException e) {
// TODO Auto-generated catch block
Log.i("PROBLEMA","ERROR DE DATOS");
}
}
public byte [] readMessage(){
byte[] buffer = new byte[64];
Log.i("Excelente","Entre a readmessage");
try {
InputStream inputstream = socket_nxt1.getInputStream();
inputstream.read(buffer);
//mmInStream.read(buffer);
Log.i("Excelente","Lei los datos");
for (int index = 0; index < buffer.length; index++){
Log.i("RECIBIDO:", String.format("0x%20x", buffer[index]));
}
Log.i("Excelente","Recibi datos y los escribi");
return buffer;
} catch (IOException e) {
// TODO Auto-generated catch block
Log.i("PROBLEMA","ERROR DE DATOS AL RECIBIR");
return null;
}
}
public void cancel() {
try {
//OutputStream outputStream = socket_nxt1.getOutputStream();
socket_nxt1.close();
} catch (IOException e) {
Log.e("ERROR","Unable to close");
}
}