用了android官方BLE的demo可以成功接收Arduino101板子传入的数据;
在原来的程序中直接加入打电话的代码,可以实现
private void displayData(String data) {
if (data != null) {
mDataDisplay.setText(data);
}
button = (Button) findViewById(R.id.button);
number=data;
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:000000"));
if (ActivityCompat.checkSelfPermission(DeviceControlActivity.this,
Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
return;
}
startActivity(callIntent);
}
});
————————————————————————————————
但是如果利用接收到的数据,就出现报错No Activity found to handle Intent { act=android.intent.action.CALL }
private void displayData(String data) {
if (data != null) {
mDataDisplay.setText(data);
}
button = (Button) findViewById(R.id.button);
number=data;
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent callIntent = new Intent(Intent.ACTION_CALL);
if(number.equals("00"))
{
callIntent.setData(Uri.parse("tel:000000"));
}else if(number.equals("01"))
{
callIntent.setData(Uri.parse("tel:000001"));
}else if(number.equals("02"))
{
callIntent.setData(Uri.parse("tel:000002"));
}else if(number.equals("03"))
{
callIntent.setData(Uri.parse("tel:000003"));
}else if(number.equals("04"))
{
callIntent.setData(Uri.parse("tel:000004"));
}else if(number.equals("05"))
{
callIntent.setData(Uri.parse("tel:000005"));
}
if (ActivityCompat.checkSelfPermission(DeviceControlActivity.this,
Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
return;
}
startActivity(callIntent);
}
});
日志:
04-19 21:06:06.176 28375-28430/com.example.bledemo D/BluetoothLeScanner: onScanResult() - ScanResult{mDevice=98:4F:EE:0F:C5:A3, mScanRecord=ScanRecord [mAdvertiseFlags=6, mServiceUuids=[0000180f-0000-1000-8000-00805f9b34fb], mManufacturerSpecificData={}, mServiceData={}, mTxPowerLevel=-2147483648, mDeviceName=BatteryMonitorSketch], mRssi=-35, mTimestampNanos=613094916898376}
04-19 21:06:06.196 28375-28399/com.example.bledemo D/ScanRecord: parseFromBytes
04-19 21:06:06.196 28375-28399/com.example.bledemo D/BluetoothLeScanner: onScanResult() - ScanResult{mDevice=98:4F:EE:0F:C5:A3, mScanRecord=ScanRecord [mAdvertiseFlags=6, mServiceUuids=[0000180f-0000-1000-8000-00805f9b34fb], mManufacturerSpecificData={}, mServiceData={}, mTxPowerLevel=-2147483648, mDeviceName=BatteryMonitorSketch], mRssi=-35, mTimestampNanos=613094940227543}
04-19 21:06:06.221 28375-28399/com.example.bledemo D/ScanRecord: parseFromBytes
04-19 21:06:06.221 28375-28399/com.example.bledemo D/BluetoothLeScanner: onScanResult() - ScanResult{mDevice=98:4F:EE:0F:C5:A3, mScanRecord=ScanRecord [mAdvertiseFlags=6, mServiceUuids=[0000180f-0000-1000-8000-00805f9b34fb], mManufacturerSpecificData={}, mServiceData={}, mTxPowerLevel=-2147483648, mDeviceName=BatteryMonitorSketch], mRssi=-35, mTimestampNanos=613094962124876}
04-19 21:06:06.246 28375-28375/com.example.bledemo I/System.out: ==position==0
04-19 21:06:06.246 28375-28375/com.example.bledemo D/BluetoothAdapter: stopLeScan()
04-19 21:06:06.251 28375-28375/com.example.bledemo I/Timeline: Timeline: Activity_launch_request id:com.example.bledemo time:163428963
04-19 21:06:06.266 28375-28375/com.example.bledemo D/BluetoothAdapter: stopLeScan()
04-19 21:06:06.266 28375-28375/com.example.bledemo D/BluetoothAdapter: scan not started yet
04-19 21:06:06.341 28375-28375/com.example.bledemo D/AbsListView: Get MotionRecognitionManager
04-19 21:06:06.351 28375-28375/com.example.bledemo D/Activity: performCreate Call secproduct feature valuefalse
04-19 21:06:06.351 28375-28375/com.example.bledemo D/Activity: performCreate Call debug elastic valuetrue
04-19 21:06:06.521 28375-28375/com.example.bledemo D/BluetoothGatt: connect() - device: 98:4F:EE:0F:C5:A3, auto: false
04-19 21:06:06.521 28375-28375/com.example.bledemo D/BluetoothGatt: registerApp()
04-19 21:06:06.521 28375-28375/com.example.bledemo D/BluetoothGatt: registerApp() - UUID=fd636193-9b1f-4767-b799-d2eae15bcfc0
04-19 21:06:06.561 28375-28375/com.example.bledemo D/BluetoothLeService: Trying to create a new connection.
04-19 21:06:06.561 28375-28399/com.example.bledemo D/BluetoothGatt: onClientRegistered() - status=0 clientIf=7
04-19 21:06:06.671 28375-28388/com.example.bledemo D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=7 device=98:4F:EE:0F:C5:A3
04-19 21:06:06.676 28375-28375/com.example.bledemo I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@19af1c7c time:163429389
04-19 21:06:06.681 28375-28388/com.example.bledemo I/BluetoothLeService: Connected to GATT server.
04-19 21:06:06.681 28375-28388/com.example.bledemo D/BluetoothGatt: discoverServices() - device: 98:4F:EE:0F:C5:A3
04-19 21:06:06.686 28375-28388/com.example.bledemo I/BluetoothLeService: Attempting to start service discovery:true
04-19 21:06:06.691 28375-28388/com.example.bledemo D/BluetoothGatt: onSearchComplete() = Device=98:4F:EE:0F:C5:A3 Status=0
04-19 21:06:06.941 28375-28375/com.example.bledemo V/ActivityThread: updateVisibility : ActivityRecord{3970b103 token=android.os.BinderProxy@21371bc6 {com.example.bledemo/com.example.bledemo.DeviceScanActivity}} show : false
04-19 21:06:08.126 28375-28375/com.example.bledemo D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
04-19 21:06:08.651 28375-28375/com.example.bledemo D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
04-19 21:06:08.796 28375-28375/com.example.bledemo D/BluetoothGatt: setCharacteristicNotification() - uuid: 00002a19-0000-1000-8000-00805f9b34fb enable: true
04-19 21:06:10.286 28375-28375/com.example.bledemo D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
04-19 21:06:10.366 28375-28375/com.example.bledemo D/Instrumentation: checkStartActivityResult :Intent { act=android.intent.action.CALL }
04-19 21:06:10.366 28375-28375/com.example.bledemo D/Instrumentation: checkStartActivityResult inent is instance of inent:
04-19 21:06:10.366 28375-28375/com.example.bledemo D/AndroidRuntime: Shutting down VM
04-19 21:06:10.371 28375-28375/com.example.bledemo E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.bledemo, PID: 28375
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.CALL }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1801)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1499)
at android.app.Activity.startActivityForResult(Activity.java:3942)
at android.app.Activity.startActivityForResult(Activity.java:3889)
at android.app.Activity.startActivity(Activity.java:4213)
at android.app.Activity.startActivity(Activity.java:4181)
at com.example.bledemo.DeviceControlActivity$5.onClick(DeviceControlActivity.java:299)
at android.view.View.performClick(View.java:5184)
at android.view.View$PerformClick.run(View.java:20910)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5942)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)