通知如果蓝牙在Android应用程序关闭 [英] notification if the Bluetooth is turned off in android app

查看:293
本文介绍了通知如果蓝牙在Android应用程序关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即时通讯目前正在对Android应用程序.. 我必须通知用户只要蓝牙 该装置的被关断,而应用程序是 当前正在运行的.. 如何通知远程设备达BT是 关掉? 在此先感谢

Im currently working on a android application.. I have to notify the user whenever the bluetooth of the device is turned off while the application is currently running.. How to notify the remote device tat BT is turned off? Thanks in advance

推荐答案

注册的BroadcastReceiver 意图的行动 BluetoothAdapter.ACTION_STATE_CHANGED ,拨动您的notifiyng code转换的onReceive 方法。不要忘记检查,如果新的状态为OFF

Register BroadcastReceiver with intent action BluetoothAdapter.ACTION_STATE_CHANGED and move your notifiyng code into onReceive method. Don't forget to check if new state is OFF

if(BluetoothAdapter.ACTION_STATE_CHANGED.equals(intent.getAction())) {
    if(intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1) 
        == BluetoothAdapter.STATE_OFF)
        // Bluetooth was disconnected
}

这篇关于通知如果蓝牙在Android应用程序关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆