0

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

问题发生在 ANPServerService 类扩展服务,所以我不能在那里定义我的 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);
        }
    }
4

0 回答 0