用了android官方BLE的demo可以成功接收Arduino101板子传入的数据;
在原来的程序中直接加入打电话的代码,可以成功拨打电话
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gatt_services_characteristics);
final Intent intent = getIntent();
mDeviceName = intent.getStringExtra(EXTRAS_DEVICE_NAME);
mDeviceAddress = intent.getStringExtra(EXTRAS_DEVICE_ADDRESS);
// Sets up UI references.
((TextView) findViewById(R.id.device_address)).setText(mDeviceAddress);
mGattServicesList = (ExpandableListView) findViewById(R.id.gatt_services_list);//characteristics列表
mGattServicesList.setOnChildClickListener(servicesListClickListner);
mConnectionState = (TextView) findViewById(R.id.connection_state);
mDataDisplay = (TextView) findViewById(R.id.data_value);
getActionBar().setTitle(mDeviceName);
getActionBar().setDisplayHomeAsUpEnabled(true);
Intent gattServiceIntent = new Intent(this, BluetoothLeService.class);
bindService(gattServiceIntent, mServiceConnection, BIND_AUTO_CREATE);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:000000"));
}
}
});
}
但如果改成根据数据的不同,拨打不同电话,就会停止工作,并且报错No Activity found to handle Intent { act=android.intent.action.CALL }
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gatt_services_characteristics);
final Intent intent = getIntent();
mDeviceName = intent.getStringExtra(EXTRAS_DEVICE_NAME);
mDeviceAddress = intent.getStringExtra(EXTRAS_DEVICE_ADDRESS);
// Sets up UI references.
((TextView) findViewById(R.id.device_address)).setText(mDeviceAddress);
mGattServicesList = (ExpandableListView) findViewById(R.id.gatt_services_list);//characteristics列表
mGattServicesList.setOnChildClickListener(servicesListClickListner);
mConnectionState = (TextView) findViewById(R.id.connection_state);
mDataDisplay = (TextView) findViewById(R.id.data_value);
getActionBar().setTitle(mDeviceName);
getActionBar().setDisplayHomeAsUpEnabled(true);
Intent gattServiceIntent = new Intent(this, BluetoothLeService.class);
bindService(gattServiceIntent, mServiceConnection, BIND_AUTO_CREATE);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent callIntent = new Intent(Intent.ACTION_CALL);
if (number == "00") {
callIntent.setData(Uri.parse("tel:000000"));
startActivity(callIntent);
}else if (number == "01") {
callIntent.setData(Uri.parse("tel:000001"));
startActivity(callIntent);
}else if (number == "02") {
callIntent.setData(Uri.parse("tel:000002"));
startActivity(callIntent);
}else if (number == "03") {
callIntent.setData(Uri.parse("tel:000003"));
startActivity(callIntent);
}else if (number == "04") {
callIntent.setData(Uri.parse("tel:000004"));
startActivity(callIntent);
}else if (number == "05") {
callIntent.setData(Uri.parse("tel:000005"));
startActivity(callIntent);
}
}
});
}
麻烦各位大神帮忙看一下!!!谢谢!!!