How catch android dispatchKeyEvent in nativescript app?

我们两清 提交于 2020-06-29 03:47:14

问题


Extended dispatchKeyEvent in Activity for listening volume up/down key press events in android.

(as described here: How to listen for volume up/down key in android with nativescript?)

But can't figure out how to catch this events in app.

This process described here with all events but dispatchKeyEvent: https://docs.nativescript.org/core-concepts/application-lifecycle#android-activity-events

application.android.on( <what should be here?>, function (args) {
    console.log("Event: " + args.eventName + ", Activity: " + args.activity);
});

回答1:


activity.android.js

case android.view.KeyEvent.KEYCODE_VOLUME_UP:
application.notify({
    eventName:'KEYCODE_VOLUME_UP',
})
// console.log("KEYCODE_VOLUME_UP");
return true;

inside application

    const application = require("tns-core-modules/application");
    if (application.android) {
      application.on('KEYCODE_VOLUME_UP', this.onVolumeUp);
      application.on('KEYCODE_VOLUME_DOWN', this.onVolumeDown);
    }


来源:https://stackoverflow.com/questions/62381277/how-catch-android-dispatchkeyevent-in-nativescript-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!