当我正在开发一个应显示可以在我的环境中连接的蓝牙设备的应用程序时,我正在尝试使用BroadcastReceiver列出它们。但是实际上没有列出任何设备,并且onReceive函数也不会触发。

我的清单中也获得了蓝牙的许可...

活动代码

Button button_connect_bluetooth;

LinearLayout linearLayout_bluetooth_devices;

TextView textView_devices[]= new TextView[200];

int index_device =0;

private BluetoothAdapter mBluetoothAdapter;

@SuppressLint("WrongViewCast")

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_connection);

button_connect_bluetooth =(Button) findViewById(R.id.button_connect_bluetooth);

linearLayout_bluetooth_devices = (LinearLayout) findViewById(R.id.linearLayout_bluetooth_devices);

makeDiscoverable();

mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

mBluetoothAdapter.startDiscovery();

IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);

registerReceiver(myReceiver, filter);

}

@Override

protected void onDestroy() {

unregisterReceiver(myReceiver);

super.onDestroy();

}

//Handy für 300 Sekunden sichtbar machen

private void makeDiscoverable() {

Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);

discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);

startActivity(discoverableIntent);

}

private final BroadcastReceiver myReceiver = new BroadcastReceiver() {

@Override

public void onReceive(Context context, Intent intent) {

String action = intent.getAction();

if(BluetoothDevice.ACTION_FOUND.equals(action)){

//Gefundene Objekte in die Liste hinzufügen

BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

textView_devices[index_device]= new TextView(Connection.this);

textView_devices[index_device].setTextColor(Color.parseColor("#00ADEF"));

textView_devices[index_device].setTextSize(12);

textView_devices[index_device].setId(index_device);

textView_devices[index_device].setText(device.getName());

textView_devices[index_device].setPadding(15, 0, 0, 0);

textView_devices[index_device].setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.list_overview_textviews_design, null));

linearLayout_bluetooth_devices.addView(textView_devices[index_device]);

index_device++;

showDeviceFoundToast("Found device " + device.getName());

}

}

};

public void showDeviceFoundToast (String message){

Toast.makeText(Connection.this, message,

Toast.LENGTH_LONG).show();

}

}

Manifest.xml

我正在具有Android 10的三星Galaxy A51上尝试此应用...

如果有人可以帮助我,那将是很好!

android 不定时搜不到蓝牙广播,找不到带有Android Studio BroadcastReceiver的蓝牙设备吗?...相关推荐

  1. mac搜索不到共享计算机,mac蓝牙搜索找不到设备怎么处理 Mac蓝牙设备连不上的解决方法有哪些...

    今天给大家带来mac蓝牙搜索找不到设备怎么处理,Mac蓝牙设备连不上的解决方法有哪些,让您轻松解决问题. mac蓝牙搜索找不到设备怎么办 Mac蓝牙设备连不上的原因解决方法.我们现在有很多人都在使用苹 ...

  2. android 蓝牙 广播,android蓝牙BLE(三) —— 广播

    ​ 在蓝牙开发中,有些情况是不需要连接的,只要外设广播自己的数据即可,例如苹果的ibeacon.自Android 5.0更新蓝牙API后,手机可以作为外设广播数据. 广播包有两种: 广播包(Adver ...

  3. 【Android】Audio音频输出通道切换 - 蓝牙bluetooth、外放

    参考: [Android]Audio音频输出通道切换 - 蓝牙.外放 Android Audio 音频输出通道切换 为什么 iOS 或 Android 设备连接蓝牙设备后不能通过蓝牙设备接电话? xq ...

  4. 【Android】Audio音频输出通道切换 - 蓝牙、外放

    手机音频的输出有外放(Speaker).听筒(Telephone Receiver).有线耳机(WiredHeadset).蓝牙音箱(Bluetooth A2DP)等输出设备.在平时,电话免提.插拔耳 ...

  5. android 取消蓝牙配对框 实现自动配对,android 取消蓝牙配对框 实现自动配对

    我看了几个文章,主要是接受配对广播,然后设置pin,实现配对,但是网上的大部分手机是不可以的,android.bluetoothdevice 下 action_pair_request ,没有定义这个 ...

  6. 高通平台 android 12 定时开关机

    高通平台 android 12 定时开关机 关机 关机实现 开机实现 总结 关机 AlarmManager取消了RTC_POWEROFF_WAKEUP 不支持通过AlarmManager设置关机唤醒设 ...

  7. 蓝牙广播数据包_蓝牙BLE数据包格式汇总

    以蓝牙4.0为例说明: BLE包格式有:广播包.扫描包.初始化连接包.链路层控制包(LL层数据包).逻辑链路控制和自适应协议数据包(即L2CAP数据包)等: 其中广播包又分为:定向广播包和非定向广播包 ...

  8. Android每天定时提醒功能、定时功能、闹钟

    这个是设置定时提醒的功能,即设置几点几分后提醒,用的是给系统设置个时间点,当系统时间到达设置的时间点的时候就会给我们发送一个广播,然后达到时间提醒功能 网上找了很多,遇到了很多坑,经过摸索出来的,比如 ...

  9. BLE广播流程介绍 蓝牙广播 低功耗蓝牙广播的实现流流程介绍 /BLE Advertising flow ----- 蓝牙低功耗协议栈

    零. 概述 主要介绍下蓝牙协议栈(bluetooth stack)低功耗蓝牙广播的流程以及协议栈的实现流程,BLE  Advertising flow btsnoop以及流程在资料中的......\S ...

最新文章

  1. 雷军的100亿计划:不服就干,生死看淡
  2. python上海培训哪里比较好-python培训机构上海哪里好?
  3. 你的第一个AngularJS应用--教程二:基架、建立和測试的工具
  4. 系统架构面临的三大挑战,看 Kubernetes 监控如何解决?
  5. JDK中没有jre文件夹和tools.jar文件
  6. pmp每日三题(2022年2月23日)
  7. 分享:MetaModel 3.2.5 发布,数据库元模型
  8. python图形界面教程_图形教程
  9. 用1、2、2、3、4、5这六个数字,用java写一个main函数,打印出所有不同的排列,如:512234、412345等,要求:4不能在第三位,3与5不能相连。...
  10. JimuReport积木报表——主子报表如何设计
  11. jbox弹窗_关于使用 jBox 对话框的提交不能弹出问题解决方法
  12. linux zk服务 关闭_linux上安装zookeeper 启动和关闭的教程
  13. php变形的itf条码,itf14条码生成器 第14章生成器.doc
  14. 计算机数学公式画爱心教程,几何画板如何绘制爱心?几何画板爱心函数教程
  15. 【目标检测】xmin,ymin,width,height 转为 xmin,ymin,xmax,ymax
  16. python输出到文件里
  17. 使用Freemark和aspose.word实现动态word转pdf
  18. 简单的购物车和购物车结算
  19. 区块链发展,能源领域不能盲目跟风!
  20. Nexys video ftp搭建和传输

热门文章

  1. Wannafly挑战赛29-A御坂美琴 (dfs+map)
  2. [计蒜客][贪心]节约用电
  3. 笔记本wifi突然消失,出现BUGCODE_NDIS_DRIVER蓝屏错误代码
  4. CF817D【Imbalanced Array】
  5. 【Proteus仿真】51单片机+LCD1602驱动模板
  6. java 秒表_Java的秒表类
  7. vue3点击返回顶部
  8. 阿里国际数字商业持续增长背后,蒋凡正在经历“考验”
  9. 总结:Prometheus匹配模式
  10. android 4.0.4系统添加波斯语