从服务中的EditText发送文本

时间:2013-05-04 18:37:22

标签: java android

我从Samsung BLE SDK网站下载了一个BLE示例,我想编辑此代码。我想在Edittext中写一个值,并按下按钮发送该值。在此示例中,它发送字符串dummyName =“Praveen”,而我想更改它。

问题是ANPServerService类扩展了Service,所以我无法在那里定义我的EditText。我只想在EditText中发送文本而不是“dummyName”字符串。我该怎么办?。

ANPServerService部分:

public class ANPServerService extends Service {

  public static String dummyName = "Praveen";


  public void sendAlert(BluetoothDevice device) {
    Log.d(TAG, "sendAlert");
    byte[] value = null;
    byte cat = (byte) callCategory;
    byte cnt = (byte) dummyCount;

    try {
        String s = dummyName;           
        value = s.getBytes("UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    byte[] attVal = new byte[value.length + 2];

    attVal[0] = cat;
    attVal[1] = cnt;
    for (int i = 0; i < value.length; i++)
        attVal[i + 2] = value[i];

    mNewAlert.setValue(attVal);
    mBluetoothGattServer.notifyCharacteristicChanged(device, mNewAlert, false);

}

主要活动部分:

public class MainActivity extends Activity implements Button.OnClickListener {

    public void onClick(View v) {
        switch (v.getId()) {          
                 case R.id.button_send_alert:
                     Log.e("MainActivity", "Clicked");
                     if (mService != null)
                         mService.sendAlert(mDevice);
        }
    }

0 个答案:

没有答案