简体   繁体   English

Android是否支持检测硬件中断?

[英]Does Android support the detection of hardware interrupts?

Suppose I'm working on an Android application. 假设我正在开发一个Android应用程序。 Suddenly I connect my Android phone to my computer. 突然我将Android手机连接到计算机。 Does Android have a mechanism to detect such hardware interrupts? Android是否具有检测此类硬件中断的机制?

Yes, the linux kernel that is running in the background can handle interrupts. 是的,在后台运行的linux内核可以处理中断。

You can even take a look at them by typing: 您甚至可以通过键入以下内容来查看它们:

cat /proc/interrupts

in the adb shell. 在adb shell中。

There's also ways to detect these types of things through Intents and BroadcastReceivers, ie 还有一些方法可以通过Intent和BroadcastReceivers来检测这些类型的事物,即

http://developer.android.com/reference/android/content/Intent.html#ACTION_POWER_DISCONNECTED 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 (ie in your Activity class), something like this: 如果以这种方式进行操作,则需要编写一个扩展BroadcastReceiver的类( http://developer.android.com/reference/android/content/BroadcastReceiver.html ),并实现onReceive(),然后注册您的接收器某个地方(即在您的Activity类中),如下所示:

MyReceiver receiver = new MyReceiver(); 
IntentFilter inf = new IntentFilter(); 
inf.addAction(Intent.ACTION_POWER_DISCONNECTED); 
this.registerReceiver(receiver , inf);

Also, you'll have to add that receiver to your AndroidManifest.xml : 另外,您还必须将该接收器添加到您的AndroidManifest.xml中:

<application .. >
...
    <receiver android:enabled="true"
         android:exported="false"
         android:label="string resource"
         android:name=".MyReceiver"
    >
    </receiver>
</application>

Then onReceive() should get called whenever the Action happens (in this case, whenever ACTION_POWER_DISCONNECTED happens). 然后,只要操作发生(在这种情况下,只要ACTION_POWER_DISCONNECTED发生),就应该调用onReceive()。

Hope that helps! 希望有帮助!

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. 是的,Android操作系统始终会观察到中断,并且基本上对于所有系统行为和事件,android都会负责通知与该特定事件或中断相关的用户。

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. 例如USB连接,电池电量低或任何单击或触摸事件等。

The device firmware is responsible for transmitting these signals from the hardware and then any kind of interrupt will be caught by I2C bus. 设备固件负责从硬件传输这些信号,然后I2C总线会捕获任何类型的中断。

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. 然后,这些信号将由Linux内核中的设备驱动程序解码。输入设备驱动程序负责通过Linux输入协议将特定于设备的信号转换为标准输入事件格式。

Android EventHub component reads input events from the kernel. Android EventHub组件从内核读取输入事件。

Finally, the InputReader sends input events to the InputDispatcher which forwards them to the appropriate window. 最后,InputReader将输入事件发送到InputDispatcher,后者将它们转发到适当的窗口。

This is definitely not the android way of doing things. 这绝对不是android的处理方式。 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM