Coder Social home page Coder Social logo

Comments (3)

giantsol avatar giantsol commented on July 18, 2024

Hi @nexussmart ,

In normal Android development(i.e. native Android), it is very easy to detect volume button events without requesting ACTION_MANAGER_OVERLAY_PERMISSION that we request here. You can just override onKeyDown method in your Activity.

However, flutter plugin environment provides very limited api, and there was no easy way to implement volume detection except what we did in this plugin. So.. as far as it seems now, ACTION_MANAGER_OVERLAY_PERMISSION is necessary.

Besides, the link you shared with us is only for Cordova, and its development environment is different from that of flutter plugin, so it couldn't be our option :(

Thanks.

from flutter_hardware_buttons.

nexussmart avatar nexussmart commented on July 18, 2024

Hi @giantsol,

I override the mainactivity to detect event key Volume Up and Down :

`

public static final String STREAM = "com.enterprise.eventkeychannel/stream";

private EventChannel.EventSink eventSink = null;

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
new EventChannel(getFlutterView(), STREAM).setStreamHandler(
  new EventChannel.StreamHandler() {
      @Override
      public void onListen(Object args, final EventChannel.EventSink events) {
          eventSink = events;
      }
      @Override
      public void onCancel(Object args) {
          eventSink = null;
      }
  }
 );
}
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
  if(event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN) {
    if( eventSink != null) { eventSink.success(0); }
  } else {
    if(event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP) {
      if( eventSink != null) { eventSink.success(1); }
    }
  }
  return super.dispatchKeyEvent(event);
}`

from flutter_hardware_buttons.

giantsol avatar giantsol commented on July 18, 2024

Yep, that's exactly what you can do if it's your own app.
However, in our case, as we're developing a plugin, we cannot override your(or other app's) MainActivity, so we can't take the easy way that you just implemented.

You just wrote your own EventChannel!
Congratulations! ๐Ÿ’ช๐Ÿป

from flutter_hardware_buttons.

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.