Android支持硬件中断检测吗?
假设我正在开发一个 Android 应用程序。突然我将我的 Android 手机连接到我的电脑。 Android有检测此类硬件中断的机制吗?
Suppose I'm working on an Android application. Suddenly I connect my Android phone to my computer. Does Android have a mechanism to detect such hardware interrupts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
是的,在后台运行的linux内核可以处理中断。
输入:来查看它们。
您甚至可以通过在 adb shell 中
Yes, the linux kernel that is running in the background can handle interrupts.
You can even take a look at them by typing:
in the adb shell.
还有一些方法可以通过 Intents 和 BroadcastReceiver 来检测这些类型的事情,即
http: //developer.android.com/reference/android/content/Intent.html#ACTION_POWER_DISCONNECTED
如果您这样做,您将需要编写一个扩展 BroadcastReceiver 的类( http://developer.android.com/reference/android/content/BroadcastReceiver.html ),并实现onReceive(),然后在某个地方(即在您的 Activity 类中)注册您的接收器,如下所示:
另外,您必须将该接收器添加到您的 AndroidManifest.xml 中:
然后每当 Action 发生时(在在这种情况下,每当 ACTION_POWER_DISCONNECTED 发生时)。
希望有帮助!
There's also ways to detect these types of things through Intents and BroadcastReceivers, i.e.
http://developer.android.com/reference/android/content/Intent.html#ACTION_POWER_DISCONNECTED
If you do things this way, you'll want to write a class that extends BroadcastReceiver ( http://developer.android.com/reference/android/content/BroadcastReceiver.html ), and implement onReceive(), then register your receiver somewhere (i.e. in your Activity class), something like this:
Also, you'll have to add that receiver to your AndroidManifest.xml :
Then onReceive() should get called whenever the Action happens (in this case, whenever ACTION_POWER_DISCONNECTED happens).
Hope that helps!
是的,Android 操作系统始终观察中断,并且基本上对于所有系统行为和事件,Android 都会负责通知与该特定事件或中断相关的用户。
首先,中断只不过是用户的操作或系统状态的改变。例如 USB 连接、电池电量低或任何点击或触摸事件等。
设备固件负责从硬件传输这些信号,然后任何类型的中断将被 I2C 总线捕获。
然后这些信号将被Linux内核中的设备驱动程序解码
输入设备驱动程序负责通过 Linux 输入协议将设备特定信号转换为标准输入事件格式。
Android EventHub 组件从内核读取输入事件。
最后,InputReader 将输入事件发送到InputDispatcher,后者将它们转发到适当的窗口。
Yes, Android operating system always observes an interrupt and basically for all the system behavior and events android takes care of informing to the user related that particular event or interrupt.
First of all the interrupts are nothing but an action by the user or state change of system. for example USB connection, battery low or any click or touch event etc.
The device firmware is responsible for transmitting these signals from the hardware and then any kind of interrupt will be caught by I2C bus.
Then these signals will be decoded by the device driver in the Linux kernel
The input device drivers are responsible for translating device-specific signals into a standard input event format, by way of the Linux input protocol.
Android EventHub component reads input events from the kernel.
Finally, the InputReader sends input events to the InputDispatcher which forwards them to the appropriate window.
这绝对不是 Android 的做事方式。手机插拔时都有广播可供收听
This is definitely not the android way of doing things. There are broadcasts to listen for when the phone is plugged in and unplugged
在frameworks\base\services\java\com\android\server 中查找UEventObserver.java,在frameworks\base\core\java\android\os 中查找SystemServer.java
Look for UEventObserver.java in frameworks\base\services\java\com\android\server and SystemServer.java in frameworks\base\core\java\android\os