开发者

Does Android support the detection of hardware interrupts?

Suppose I'm working on an Android application. Suddenly I connect my Android phone to my computer. Does Android have a mechanism to d开发者_StackOverflow中文版etect such hardware interrupts?


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.


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!


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.


This is definitely not the android way of doing things. There are broadcasts to listen for when the phone is plugged in and unplugged


Look for UEventObserver.java in frameworks\base\services\java\com\android\server and SystemServer.java in frameworks\base\core\java\android\os

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜