如何使用nativescript在android中收听音量调高/调低键? [英] How to listen for volume up/down key in android with nativescript?

查看:60
本文介绍了如何使用nativescript在android中收听音量调高/调低键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想知道如何访问本机脚本中的音量调高和调低键.

I just want to know how to access volume up and down key in native script.

推荐答案

要在NativeScript中做到这一点,您可以使用James提供的代码并扩展Android NativeScript应用程序的主要活动.下面,我将描述使用TypeScript项目实现该功能所需的步骤.

To do that in NativeScript you can use the code provided by James and extend the main activity for your Android NativeScript application. Below I am going to describe the steps needed to achieve that functionality with TypeScript project.

  • 在名为activity.android.ts

扩展了Activity并覆盖了dispatchKeyEvent 此处在我的演示应用程序中

in the newly created file extend the Activity and overwrite dispatchKeyEvent as done here in my demonstration application

最后,

lastly, provide the new activity to your AndroidManifest file by replacing the default one created by NativeScript

可以在此处找到演示该技术的整个演示应用程序. 可以在此处(TypeScript和Vanilla JavaScript示例).

The whole demo application demonstrating the technique can be found here. Article section on how to extend the Android Activity in NativeScript can be found here (both TypeScript and vanilla JavaScript example).

这篇关于如何使用nativescript在android中收听音量调高/调低键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆