Android支持硬件中断检测吗?

发布于 2024-09-16 19:09:14 字数 77 浏览 4 评论 0原文

假设我正在开发一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

苹果你个爱泡泡 2024-09-23 19:09:14

是的,在后台运行的linux内核可以处理中断。

输入:来查看它们。

cat /proc/interrupts

您甚至可以通过在 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:

cat /proc/interrupts

in the adb shell.

我的奇迹 2024-09-23 19:09:14

还有一些方法可以通过 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 类中)注册您的接收器,如下所示:

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

另外,您必须将该接收器添加到您的 AndroidManifest.xml 中:

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

然后每当 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:

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 :

<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).

Hope that helps!

我们的影子 2024-09-23 19:09:14

是的,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.

土豪我们做朋友吧 2024-09-23 19:09:14

这绝对不是 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

吾家有女初长成 2024-09-23 19:09:14

在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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文