Method for Android to check battery power (based on broadcastreceiver)

This article gives an example of how Android can check the battery power. Share with you for your reference, as follows:

The procedure is as follows:

In Android, android.intent.battery_ Changed is the broadcast action message of the system. When the battery is in the charging state or the battery power changes, the system will broadcast this action; During the registration of the broadcastreceiver in the program, the intent filter is set to filter this action information. Therefore, once the broadcastreceiver is registered, it can immediately capture this action and obtain the battery power. Onreceiver () in the main program is the method that will run when broadcastreceiver is triggered. It is written as follows:

Add this judgment intent.action_ BATTERY_ Changed. Equals (action) is to ensure that broadcastreceiver will only be changed by intent. Action_ BATTERY_ Changed this trigger. Without this judgment, the program can run.

It is stated in the Android API that you need to register with intent.action_ BATTERY_ The changed receiver can only be registered in the program in the form of context. Registerreceiver(), not directly in androidmanifest.xml.

In this example, the dialog is used to make the background window appear fuzzy when it pops up:

Where windowmanager.layoutparams.flag_ BLUR_ Behind tells the current window that no matter what object is displayed on the front end, it will appear on the top layer of the window, making the background window appear blurred. You can also use this effect in other programs.

More readers interested in Android related content can view the special topics of this site: Android control usage summary and Android development introduction and advanced tutorial

I hope this article will help you in Android programming.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>