日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android 屏幕灭屏亮屏广播,屏幕灭屏亮屏监听,广播实现按键监听

發(fā)布時(shí)間:2023/12/10 Android 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android 屏幕灭屏亮屏广播,屏幕灭屏亮屏监听,广播实现按键监听 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

service 類注冊(cè)廣播進(jìn)行監(jiān)聽

/*** 作者:created by meixi* 郵箱:13164716840@163.com* 日期:2018/9/27 09*/ public class Serview extends Service {/*** 廣播接受者*/private BroadcastReceiver mBatInfoReceiver;private String TAG = "lgq--------------------";@Overridepublic void onCreate() {super.onCreate(); // Log.d(TAG, "onCreate()"); // initNotification(); // initTodayData();initBroadcastReceiver(); // new Thread(new Runnable() { // public void run() { // startStepDetector(); // } // }).start(); // startTimeCount();}/*** 注冊(cè)廣播*/private void initBroadcastReceiver() {final IntentFilter filter = new IntentFilter();// 屏幕滅屏廣播filter.addAction(Intent.ACTION_SCREEN_OFF);//關(guān)機(jī)廣播filter.addAction(Intent.ACTION_SHUTDOWN);// 屏幕亮屏廣播filter.addAction(Intent.ACTION_SCREEN_ON);// 屏幕解鎖廣播 // filter.addAction(Intent.ACTION_USER_PRESENT);// 當(dāng)長按電源鍵彈出“關(guān)機(jī)”對(duì)話或者鎖屏?xí)r系統(tǒng)會(huì)發(fā)出這個(gè)廣播// example:有時(shí)候會(huì)用到系統(tǒng)對(duì)話框,權(quán)限可能很高,會(huì)覆蓋在鎖屏界面或者“關(guān)機(jī)”對(duì)話框之上,// 所以監(jiān)聽這個(gè)廣播,當(dāng)收到時(shí)就隱藏自己的對(duì)話,如點(diǎn)擊pad右下角部分彈出的對(duì)話框filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);//監(jiān)聽日期變化filter.addAction(Intent.ACTION_DATE_CHANGED);filter.addAction(Intent.ACTION_TIME_CHANGED);filter.addAction(Intent.ACTION_TIME_TICK);mBatInfoReceiver = new BroadcastReceiver() {@Overridepublic void onReceive(final Context context, final Intent intent) {String action = intent.getAction();if (Intent.ACTION_SCREEN_ON.equals(action)) {Log.i(TAG, "screen on");} else if (Intent.ACTION_SCREEN_OFF.equals(action)) {Log.i(TAG, "screen off");//改為60秒一存儲(chǔ) // duration = 60000;} else if (Intent.ACTION_USER_PRESENT.equals(action)) {Log.i(TAG, "screen unlock"); // save();//改為30秒一存儲(chǔ) // duration = 30000;} else if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(intent.getAction())) {Log.i(TAG, " receive Intent.ACTION_CLOSE_SYSTEM_DIALOGS");//保存一次 // save();} else if (Intent.ACTION_SHUTDOWN.equals(intent.getAction())) {Log.i(TAG, " receive ACTION_SHUTDOWN"); // save();} else if (Intent.ACTION_DATE_CHANGED.equals(action)) {//日期變化步數(shù)重置為0 // Logger.d("重置步數(shù)" + StepDcretor.CURRENT_STEP); // save(); // isNewDay();} else if (Intent.ACTION_TIME_CHANGED.equals(action)) {//時(shí)間變化步數(shù)重置為0Log.i("lgq000000000000","sssss時(shí)間變化步數(shù)重置為0===="+action); // isCall(); // save(); // isNewDay();} else if (Intent.ACTION_TIME_TICK.equals(action)) {//日期變化步數(shù)重置為0Log.i("lgq0000000000000000","日期變化步數(shù)重置為0===="+action); // isCall(); // Logger.d("重置步數(shù)" + StepDcretor.CURRENT_STEP); // save(); // isNewDay();}}};registerReceiver(mBatInfoReceiver, filter);}@Nullable@Overridepublic IBinder onBind(Intent intent) {return null;} }

<service android:name=".testt.Serview"><intent-filter><!-- 系統(tǒng)啟動(dòng)完成后會(huì)調(diào)用--><action android:name="android.intent.action.BOOT_COMPLETED" /><action android:name="android.intent.action.DATE_CHANGED" /><action android:name="android.intent.action.MEDIA_MOUNTED" /><action android:name="android.intent.action.USER_PRESENT" /><action android:name="android.intent.action.ACTION_TIME_TICK" /><action android:name="android.intent.action.ACTION_POWER_CONNECTED" /><action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" /></intent-filter> </service>

/*** 開啟計(jì)步服務(wù)*/private void setupService() {Intent intent = new Intent(this, Serview.class); // isBind = bindService(intent, conn, Context.BIND_AUTO_CREATE);startService(intent);}

?

實(shí)現(xiàn)demo:安卓廣播監(jiān)聽按鍵事件和屏幕熄屏亮屏監(jiān)聽-Android文檔類資源-CSDN下載?

總結(jié)

以上是生活随笔為你收集整理的Android 屏幕灭屏亮屏广播,屏幕灭屏亮屏监听,广播实现按键监听的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。