Android中广播优先级设置

xiaoxiao2021-02-28  40

Android广播优先级设置

由于开机时,接收到的广播的时间比较后,导致有些操作没来得及做 这时可以使用setPriority来提高当前Intent的优先级,使得可以在广播发出时,马上就可以收到了。优先级权限设置成IntentFilter.SYSTEM_HIGH_PRIORITY即可。

范例如下:

IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_SCREEN_ON); filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); mContext.registerReceiver( new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals(Intent.ACTION_SCREEN_ON)) { handleScreenStateChanged(); } }, filter);
转载请注明原文地址: https://www.6miu.com/read-2620115.html

最新回复(0)