开发者

How to work with android's existing BlueToothChat Application

开发者 https://www.devze.com 2023-03-18 19:12 出处:网络
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 mobi

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消