我正在 Android 开发者网站上的蓝牙聊天应用程序的帮助下开发一个蓝牙聊天应用程序。
当我将蓝牙聊天请求发送到另一台设备(假设我们之前已配对)并且请求接收设备驻留在任何活动中时,我对现有代码进行了一些修改。
我想在当前显示屏幕上显示警报,但我只在特定活动中收到警报。所以我被卡住了。我的发送方和接收方代码如下:
if (FaceCardList.requestConnection &&
FaceCardList.deviceSelected) {
String authorization = "messagetype:startChat,"
+ FaceCardList.ScreenName;
FaceCardList.this.sendMessage(authorization);
}
在接收方:
if (readMessage.indexOf("messagetype:startChat") != -1) {
AlertDialog.Builder builder =
new AlertDialog.Builder(FaceCardList.this);
builder.setMessage(
FaceCardList.screennmname + " wants to chat with you")
.setCancelable(false)
.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
Intent serverIntent = new Intent(
FaceCardList.this,
BluetoothChat.class);
startActivity(serverIntent);
String authorization = "messagetype:initiatechat";
FaceCardList.this
.sendMessage(authorization);
}
})
.setNegativeButton("No",
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface diaLog,
int which) {
// TODO Auto-generated method stub
String authorization = "messagetype:stopservice";
FaceCardList.this
.sendMessage(authorization);
FaceCardList.mChatService.stop();
FaceCardList.mChatService.start();
}
});
alert = builder.create();
alert.show();