alann-maulana / flutter_beacon

An hybrid iBeacon scanner and transmitter SDK for Flutter Android and iOS.
Apache License 2.0
116 stars 142 forks source link

failed to open Stream : RECEIVE_BOOT_COMPLETED PERMISSION #132

Open kanhaiyachatla opened 1 year ago

kanhaiyachatla commented 1 year ago

when I first implemented this plugin it was working correctly but now when I was testing I found this new Runtime exception. I cannot understand how to solve this error by reviewing some issues at StackOverflow. i tried adding this line in my androidManifest.xml but it doesn't solve my problem.

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

this is the list of permission added in the AndroidManifest.xml

`<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.digiatt_new">

<uses-permission android:name="android.permission.USE_BIOMETRIC"/>
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />`

the following code is the code that I referred to using the flutter_beacon plugin.

`import 'dart:async';
import 'dart:io' show Platform;
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:digiatt_new/Screens/AttendanceAuth.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_beacon/flutter_beacon.dart';
import 'package:local_auth/local_auth.dart';
import 'package:lottie/lottie.dart';
import 'package:permission_handler/permission_handler.dart';

class Scan extends StatefulWidget {
  var attend_data;
  var userModel;
  var classModel;
  Scan({Key? key,required this.attend_data,required this.userModel,required this.classModel}) : super(key: key);

  @override
  State<Scan> createState() => _ScanState(attend_data,userModel,classModel);
}

class _ScanState extends State<Scan> {

  final LocalAuthentication auth = LocalAuthentication();
  _SupportState __supportState = _SupportState.unknown;
  final StreamController<String> beaconEventsController = StreamController<String>.broadcast();
  String authorized = 'Not Authorized';
  bool isAuthenticating = false;
  bool authenticated = false;

  late StreamSubscription _streamRanging;
  bool isScanning = false;
  var attend_data;
  var userModel;
  var classModel;
  final regions = <Region>[];

  _ScanState(this.attend_data,this.userModel,this.classModel);

  @override
  void initState() {
    Permission.bluetoothConnect.request().then((value) {
      if(value.isGranted){
        flutterBeacon.initializeAndCheckScanning;
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Give Attendance'),
      ),
      body: Column(
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: [
          //beacon_plugin code
          ElevatedButton(onPressed: () async {
            if (Platform.isIOS) {
              // iOS platform, at least set identifier and proximityUUID for region scanning
              regions.add(Region(
                  identifier: 'Apple Airlocate',
                  proximityUUID: 'E2C56DB5-DFFB-48D2-B060-D0F5A71096E0'));
            } else {
              // android platform, it can ranging out of beacon that filter all of Proximity UUID
              regions.add(Region(identifier: 'com.beacon'));
            }

// to start ranging beacons
            _streamRanging = flutterBeacon.ranging(regions).listen((RangingResult result) {
              print(result);
              // result contains a region and list of beacons found
              // list can be empty if no matching beacons were found in range
            });
          }, child: Text('Start scan')),
          ElevatedButton(onPressed: () async {

            _streamRanging.cancel();
          }, child: Text('Stop scan')),

          Text('- Make sure your Location and Bluetooth is on. \n - Check if your Attendance details are correct')
        ],
      ),
    );
  }
kanhaiyachatla commented 1 year ago

There is one Important point to note. this error is only occurring in REDMI NOTE 10S. my primary testing device. when I tried the same app in other device. it worked perfectly. is there any problem with my device??