Code Monkey home page Code Monkey logo

Comments (16)

PetrosPoll avatar PetrosPoll commented on July 24, 2024

Is working for you on android ? I'm trying and doesn't works for android or ios. If working for your on Android please help me or send me you code.. I'm trying many days now to figure out..

Thank you!

from simple_beacons_flutter.

leobispo avatar leobispo commented on July 24, 2024

The example in the README is wrong. Use the example from the project itself

from simple_beacons_flutter.

PetrosPoll avatar PetrosPoll commented on July 24, 2024

Also project doesn't work... I'm looking so many days how to create an app that can scan beacons nearby and doing something, like notification.

from simple_beacons_flutter.

leobispo avatar leobispo commented on July 24, 2024

It is working for me... maybe your beacon?

from simple_beacons_flutter.

PetrosPoll avatar PetrosPoll commented on July 24, 2024

This example working and detect to beacons ? Hmmm my beacon is from a company blueup and from configuration app's company works well.

Can you help me to fix it and show if it works ?
Thank you.

from simple_beacons_flutter.

leobispo avatar leobispo commented on July 24, 2024

This is the code I am using:

    if (GetPlatform.isAndroid) {
      await BeaconsPlugin.setDisclosureDialogMessage(
          title: "Need Location Permission",
          message: "This app collects location data to work with beacons.");
    }

    BeaconsPlugin.listenToBeacons(beaconEventsController);

    BeaconsPlugin.setDebugLevel(2);
    await BeaconsPlugin.addRegion("myBeacon", uuid);

    beaconEventsController.stream.listen(
        (data) {
          if (data.isNotEmpty) {
            print("Beacons DataReceived: " + data);
          }
        },
        onDone: () {},
        onError: (error) {
          print("Error: $error");
        });

    await BeaconsPlugin.runInBackground(true);
    await BeaconsPlugin.startMonitoring;

    if (GetPlatform.isAndroid) {
      BeaconsPlugin.channel.setMethodCallHandler((call) async {
        await BeaconsPlugin.startMonitoring;
        if (call.method == 'scannerReady') {
          await BeaconsPlugin.startMonitoring;
        }
      });
    }
  }

from simple_beacons_flutter.

PetrosPoll avatar PetrosPoll commented on July 24, 2024

@leobispo In the addRegion the first option "myBeacon" is option and you can write what ever you want. The second is the proximityUUID?

from simple_beacons_flutter.

PetrosPoll avatar PetrosPoll commented on July 24, 2024

@leobispo I tried also your code but not working for me .. Can you help me more please ? How I can do this working ? I have spent a lot of time and I have nothing since then.

from simple_beacons_flutter.

haidvams avatar haidvams commented on July 24, 2024

here my code worked now

import 'dart:async';
import 'dart:convert';
import 'dart:io' show Platform;

import 'package:beacons_plugin/beacons_plugin.dart';
import 'package:device_info/device_info.dart';
import 'package:flutter/material.dart';
import 'package:hrm/main/data/database_helper.dart';
import 'package:hrm/main/data/rest_data.dart';
import 'package:hrm/main/models/user.dart';
import 'package:hrm/theme1/screen/attendance/T1Checkin.dart';

class BeaconScanner extends StatefulWidget {
@OverRide
_BeaconScanner createState() => _BeaconScanner();
}

class _BeaconScanner extends State {
String _beaconResult = 'Get ID device service...';
int _nrMessaggesReceived = 0;
var isRunning = false;
String _uuid;
RestDatasource api = new RestDatasource();
var db = new DatabaseHelper();
final scaffoldKey = new GlobalKey();

final StreamController beaconEventsController =
StreamController.broadcast();

_getIdAttendance() async {
dynamic id = await api.getDataPublic(
'/api/resource/Attendance%20device?fields=["uuid"]&limit_page_length=1');

if (id.isNotEmpty) {
  setState(() {
    _uuid = id.first["uuid"].toString();
    _beaconResult = 'Looking for the device...';
  });
  initPlatformState();
  await BeaconsPlugin.startMonitoring;
} else {
  _showSnackBar("Errors server HRM to get ID devece checkin");
}

}

_onCheckinSubmit() async {
String _deviceId = await _getId();
Map dataBody = await {"log_type": "IN", "device_id": _deviceId};

try {
  User user = await db.getUser();
  var res = await api.postPrivateAll(
      '/api/resource/Employee%20Checkin', user.sid, dataBody);
  if (res == true) {
    await Future<void>.delayed(Duration(milliseconds: 500));
    Navigator.pushReplacement(
        context, MaterialPageRoute(builder: (context) => T1Checkin()));
  } else {
    await Future<void>.delayed(Duration(milliseconds: 500));
    Navigator.pop(context);
  }
} catch (e) {
  print("err");
}

}

Future _getId() async {
var deviceInfo = DeviceInfoPlugin();
if (Platform.isIOS) {
// import 'dart:io'
var iosDeviceInfo = await deviceInfo.iosInfo;
return iosDeviceInfo.identifierForVendor; // unique ID on iOS
} else {
var androidDeviceInfo = await deviceInfo.androidInfo;
return androidDeviceInfo.androidId; // unique ID on Android
}
}

void _showSnackBar(String text) {
scaffoldKey.currentState
.showSnackBar(new SnackBar(content: new Text(text)));
}

@OverRide
void initState() {
super.initState();
_getIdAttendance();
}

@OverRide
void dispose() {
beaconEventsController.close();
super.dispose();
}

Future initPlatformState() async {
if (Platform.isAndroid) {
//Prominent disclosure
await BeaconsPlugin.setDisclosureDialogMessage(
title: "Need Location Permission",
message: "This app collects location data to work with beacons.");

  //Only in case, you want the dialog to be shown again. By Default, dialog will never be shown if permissions are granted.
  // await BeaconsPlugin.clearDisclosureDialogShowFlag(false);
}

BeaconsPlugin.listenToBeacons(beaconEventsController);
//ios must add uuid you want to scan
await BeaconsPlugin.addRegion(
    "ESP32", _uuid);

beaconEventsController.stream.listen(
    (data) async {
      if (data.isNotEmpty) {
        if (_uuid == jsonDecode(data)["uuid"].toString().toLowerCase()) {
          await BeaconsPlugin.stopMonitoring;
          setState(() {
            _beaconResult = "Đang checkin ...";
          });
          Future.delayed(const Duration(seconds: 1), () => "1");
          _onCheckinSubmit();
        } else {
          setState(() {
            _nrMessaggesReceived++;
          });
        }
      }
    },
    onDone: () {},
    onError: (error) {
      print("Error: $error");
    });

// Send 'true' to run in background
await BeaconsPlugin.runInBackground(true);

if (Platform.isAndroid) {
  BeaconsPlugin.channel.setMethodCallHandler((call) async {
    if (call.method == 'scannerReady') {
      await BeaconsPlugin.startMonitoring;
      setState(() {
        isRunning = true;
      });
    }
  });
} else if (Platform.isIOS) {
  await BeaconsPlugin.startMonitoring;
  setState(() {
    isRunning = true;
  });
}

if (!mounted) return;

}

Future _onBackPressed() {
return showDialog(
context: context,
builder: (context) => new AlertDialog(
title: new Text('Are you sure?'),
content: new Text('Do you want to exit Checkin'),
actions: [
new GestureDetector(
onTap: () => Navigator.of(context).pop(false),
child: Text("NO"),
),
SizedBox(height: 16),
new GestureDetector(
onTap: () async {
try {
await BeaconsPlugin.stopMonitoring;
} catch (e) {
// _showSnackBar(e.toString());
}
await Future.delayed(Duration(milliseconds: 500));

              return Navigator.of(context).pop(true);
            },
            child: Text("YES"),
          ),
        ],
      ),
    ) ??
    false;

}

@OverRide
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: _onBackPressed,
child: Scaffold(
key: scaffoldKey,
appBar: AppBar(
title: Text('Checkin'),
backgroundColor: Color(0xFF3281FF),
centerTitle: true,
),
body: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('$_beaconResult'),
Padding(
padding: EdgeInsets.all(10.0),
),
Text('$_nrMessaggesReceived'),
SizedBox(
height: 20.0,
),
// Visibility(
// visible: isRunning,
// child: RaisedButton(
// onPressed: () async {
// if (Platform.isAndroid) {
// await BeaconsPlugin.stopMonitoring;
//
// setState(() {
// isRunning = false;
// });
// }
// },
// child: Text('Stop Scanning', style: TextStyle(fontSize: 20)),
// ),
// ),
// SizedBox(
// height: 20.0,
// ),
// Visibility(
// visible: !isRunning,
// child: RaisedButton(
// onPressed: () async {
// initPlatformState();
// await BeaconsPlugin.startMonitoring;
//
// setState(() {
// isRunning = true;
// _beaconResult = "Đang tìm device...";
// });
// },
// child: Text('Start Scanning', style: TextStyle(fontSize: 20)),
// ),
// )
],
),
),
),
);
}
}

from simple_beacons_flutter.

PetrosPoll avatar PetrosPoll commented on July 24, 2024

Very nice, can you send me a link weTransfer with your code, to my email ([email protected]) please?

Thank you!

from simple_beacons_flutter.

sutogan4ik avatar sutogan4ik commented on July 24, 2024

@peterpoll you need to specify the region correctly, uuid is case-sensitive

from simple_beacons_flutter.

sutogan4ik avatar sutogan4ik commented on July 24, 2024

by the way, the implementation for android does not react at all to the scanned region, and in iOS you need to specify the region, otherwise the scan result will be ignored. in my case, I even had to change the uuid of the beacon

from simple_beacons_flutter.

cloudbreakstudios avatar cloudbreakstudios commented on July 24, 2024

by the way, the implementation for android does not react at all to the scanned region, and in iOS you need to specify the region, otherwise the scan result will be ignored. in my case, I even had to change the uuid of the beacon

Are you able to create a mini prototype of your working version? I have now spent a few days investigating why my iBeacon is not displaying on iOS.

I have setup the beacons UUID (iBeacon) and configured the code to match (also case sensitive as you've suggested). Project swift file and plist has been updated per example. Working fine on Android but absolutely no response on iOS. The location permission in settings is set to 'Always@ and there are no errors in debug.

Using BeaconSet+ app i can see the beacon straight away on the device.

I am out of ideas with this package at this point.

from simple_beacons_flutter.

cloudbreakstudios avatar cloudbreakstudios commented on July 24, 2024

So I just got this (kinda) working.. it seems that as soon as I add in more than one region to scan, iOS doesnt detect any!

This fails..
await BeaconsPlugin.addRegion("MyBeacon", "696e6974-7379-7300-0000-0070616e6963");
await BeaconsPlugin.addRegion("MyBeacon", "696e6974-7379-7300-0000-000000000001");

whereas this works and detects the first beacon..
await BeaconsPlugin.addRegion("MyBeacon", "696e6974-7379-7300-0000-0070616e6963");
//await BeaconsPlugin.addRegion("MyBeacon", "696e6974-7379-7300-0000-000000000001"); <-- commented out

Ideally I need to be able to scan for several regions (note the last 12 chars are different) as configuring the major/minor creates us an limitation that is not ideal to our use case.

Has anyone got this working where multiple regions work?

from simple_beacons_flutter.

gordett avatar gordett commented on July 24, 2024

Hello,

you put uuid in region and in ibeacon config?

i can find with android, but with iOS I can’t see any beacon. And I don’t have any error.

Any suggestion?

from simple_beacons_flutter.

gordett avatar gordett commented on July 24, 2024

Can you search beacon on ios?

from simple_beacons_flutter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.