Android already have BluetoothChat application. Using that app two devices chat with each other.
I am trying little different. Instead of chat I want whatever I write in my EditText and shake the mobile means it will appear in 2nd device.
Means BluetoothChat have one EditText and a "send" button. Whatever we write within EditText and press "send" means it send. But instead of button I want to use Sensor.
I also did the sensor for shaking separately. But problem is how can I merge both so that the bluetooth work for this.
Look at the code in this answer: Android: I want to shake it
Add the code from the above answer to the BluetoothChat activity. The following code is executed anytime the user hits the "Send" button in BluetoothChat:
public void onClick(View v) {
// Send a message using content of the edit text widget
TextView view = (TextView) findViewById(R.id.edit_text_out);
String message = view.getText().toString();
sendMessage(message);
}
Add that code (except the method declaration) to the code in the above answer, inside onSensorChanged(SensorEvent se), but ONLY if mAccel > 2.
加载中,请稍侯......
精彩评论