1.AccessibilityService無效果 接收不到onAccessibilityEvent事件
在配置好AccessibilityService后史简,而且系統(tǒng)“輔助設(shè)置”已打開配置過的AccessibilityService,剛開始能用,但莫名出現(xiàn)onAccessibilityEvent事件接收不到的情況茴晋,原因只有一條:
程序出現(xiàn)了ANR呛每,崩潰后AccessibilityServices就失效了,重啟手機即可
原文:https://blog.csdn.net/bunny1024/article/details/78139740
2.廣播監(jiān)聽android.net.conn.CONNECTIVITY_CHANGE 網(wǎng)絡(luò)變化無法收到廣播
根據(jù)https://developer.android.com/topic/performance/background-optimization的提示乓诽,api level 24以后通過manifest注冊的CONNECTIVITY_ACTION 將不再發(fā)送廣播帜羊,解決方法是通過actity的oncreate方法注冊
MyReceiver receiver=new MyReceiver();
IntentFilter filter=new IntentFilter();
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
this.registerReceiver(receiver,filter);
google文檔如下
Background processes can be memory- and battery-intensive. For example, an implicit broadcast may start many background processes that have registered to listen for it, even if those processes may not do much work. This can have a substantial impact on both device performance and user experience.
To alleviate this issue, Android 7.0 (API level 24) applies the following restrictions:
Apps targeting Android 7.0 (API level 24) and higher do not receive CONNECTIVITY_ACTION broadcasts if they declare their broadcast receiver in the manifest. Apps will still receive CONNECTIVITY_ACTION broadcasts if they register their BroadcastReceiver with Context.registerReceiver() and that context is still valid.
Apps cannot send or receive ACTION_NEW_PICTURE or ACTION_NEW_VIDEO broadcasts. This optimization affects all apps, not only those targeting Android 7.0 (API level 24).
If your app uses any of these intents, you should remove dependencies on them as soon as possible so that you can properly target devices running Android 7.0 or higher. The Android framework provides several solutions to mitigate the need for these implicit broadcasts. For example, JobScheduler and the new WorkManager provide robust mechanisms to schedule network operations when specified conditions, such as a connection to an unmetered network, are met. You can now also use JobScheduler to react to changes to content providers. JobInfo objects encapsulate the parameters that JobScheduler uses to schedule your job. When the conditions of the job are met, the system executes this job on your app's JobService.
In this document, we will learn how to use alternative methods, such as JobScheduler, to adapt your app to these new restrictions.
·
轉(zhuǎn)載自:Android無障礙和receiver的兩個注意點 - 趙席謀的個人博客 (ximouzhao.com)
更多相關(guān)內(nèi)容傳送門->趙席謀的個人博客 - (ximouzhao.com)