Code Monkey home page Code Monkey logo

flutter-proximity-sensor-plugin's Introduction

proximity_sensor

https://pub.dev/packages/proximity_sensor

simple and easy to use flutter plugin package for proximity sensor (only)

Getting started

In the pubspec.yaml of your flutter project, add the following dependency:

dependencies:
  ...
  proximity_sensor:

In your library add the following import:

import 'package:proximity_sensor/proximity_sensor.dart';

Note

Android 12 and higher are required to specify an explicit value for android:exported
This is an example.

<activity
    android:exported="true"
    ....

Regarding permissions, you may need the following settings in your AndroidManifest.xml file:

<uses-permission android:name="android.hardware.sensor.proximity"/>
<uses-permission android:name="android.permission.BODY_SENSORS_BACKGROUND"/>
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>

NB: the WAKE_LOCK permission is only needed if you run setProximityScreenOff(true) before listening to events

Some recent devices use virtual proximity sensors. There are no physical sensors. I found it hard to trust the sensor information in this case.

flutter-proximity-sensor-plugin's People

Contributors

holzgeist avatar jeremyko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

flutter-proximity-sensor-plugin's Issues

Request/Help

Can anyone help me how to toggle the screen on/off when proximity sensor value chnage

Don't pass an int but an enum with a meaning

Instead of receiving 0 or 1, it would be great to receive an enum Proximity.NEAR or Proximity.FAR. Right now, you don't know what 0 means and you have to go to the documentation. If the plugin gave a meaningful value, it would be more straightforward.

Thanks a lot for the plugin, by the way! ๐Ÿ‘๐Ÿ‘๐Ÿ‘๐Ÿ‘๐Ÿ‘

[HELP] screen not turning off on Android

Hello, using the proximity sensor turns off the screen on an iOS physical device but it doesn't turn off the screen of an Android physical device.
How would I turn off the screen? is there are any permissions I'm missing or this package doesn't support that?
Thanks!

PlatformException(error, Neither user nor current process has android.permission.WAKE_LOCK

My debug console print this whenever i'm trying to access the proximity sensor.

โ•โ•โ•โ•โ•โ•โ•โ• Exception caught by services library โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
PlatformException(error, Neither user 10539 nor current process has android.permission.WAKE_LOCK., null, null)
โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

It seems to have something to do with the recent PR commits regarding wake/sleep screen when there are objects in front of the screen. And if i added the following line to my AndroidManifest.xml.

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

Now everytime something is going near my phone screen. The screen completely shut off. This is undesired for my app (My app is device checking app and one of the test simply want to test if the proximity sensor work as expected.) as i don't want my screen to turn off. Is there anyway i can do to prevent this from happening other than downgrade to older version?

Additional Information : My device is OPPO Reno 5 Pro 5G. Android 13.

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.