我正在编写一个 android 程序,我需要将一个字符发送到另一个蓝牙设备。我写了这段程序,但是当你发送字符时,我不知道我使用的是什么功能。节目中,当事人疑点质疑。
package com.example.bl;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.*;
import android.view.*;
import android.app.*;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.content.Intent;
import android.os.Handler;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Set;
import java.util.UUID;
import java.io.*;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button bot1 = (Button) findViewById(R.id.bt1);
bot1.setOnClickListener(new View.OnClickListener(){
public void onClick(View arg0) {
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null) {
// Device does not support Bluetooth
}
int REQUEST_ENABLE_BT = 1;
if (!mBluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}
// ??????
// ??????
// ??????
// ??????
AlertDialog.Builder dialogo = new
AlertDialog.Builder(MainActivity.this);
dialogo.setTitle("Aviso");
dialogo.setMessage("Foi!");
dialogo.setNeutralButton("OK", null);
dialogo.show();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}