android8.0 BroadcastReceiver事件监听器不运行

一抹笑zZ 2019-04-11 10:58:33
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
// When discovery finds a device
Log.v("fdghdg22", "11");
Toast.makeText(Main3Activity.this, "已点击", Toast.LENGTH_LONG).show();
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
// Get the BluetoothDevice object from the Intent
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
Log.v("fdghdg11", "11");
List<String>list =new ArrayList<>();
list.add(device.getName() + "\n");
ArrayAdapter<String> mArrayAdapter=new ArrayAdapter<String>(Main3Activity.this,android.R.layout.simple_list_item_1,list);
// Add the name and address to an array adapter to show in a ListView
// mArrayAdapter.add(device.getName() + "\n" + device.getAddress());
ListView listView3=(ListView)findViewById(R.id.listView2);
listView3.setAdapter(mArrayAdapter);
}
}
};


public void onResume(){
//注册广播接收器
Log.v("fdtrtrdg", "11");
// IntentFilter intentFilter = new IntentFilter(BluetoothDevice.ACTION_FOUND);//注册广播接收信号
// intentFilter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED);//本地蓝牙适配器已经开始对远程设备的搜寻过程。
// this.registerReceiver(mReceiver, intentFilter);//用BroadcastReceiver 来取得结果
//注册广播接收器(监听蓝牙状态的改变)
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
this.registerReceiver(mReceiver, filter); // 不要忘了之后解除绑定
super.onResume();
}


warning:BroadcastQueue: Background execution not allowed: receiving Intent { act=android.intent.action.SIG_STR flg=0x10 (has extras) } to com.xingin.xhs/org.daemon.receiver.ConnectivityReceiver
...全文
162 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

50,550

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧