zoepenn 2017-04-19 12:57 采纳率: 0%
浏览 1334

Android接收arduino数据来控制打电话报错

用了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)

  • 写回答

1条回答

  • CSDN-Ada助手 CSDN-AI 官方账号 2022-09-21 07:59
    关注
    不知道你这个问题是否已经解决, 如果还没有解决的话:

    如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^
    评论

报告相同问题?

悬赏问题

  • ¥50 comsol稳态求解器 找不到解,奇异矩阵有1个空方程返回的解不收敛。没有返回所有参数步长;pid控制
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功