Java Code Examples for android.content.IntentFilter#setPriority()

The following examples show how to use android.content.IntentFilter#setPriority() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: G5CollectionService.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        initScanCallback();
    }
    advertiseTimeMS.add((long)0);

    prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    listenForChangeInSettings(true);

    // TODO check this
    //bgToSpeech = BgToSpeech.setupTTS(getApplicationContext()); //keep reference to not being garbage collected
    // handler = new Handler(getApplicationContext().getMainLooper());

    final IntentFilter bondintent = new IntentFilter(BluetoothDevice.ACTION_BOND_STATE_CHANGED);//KS turn on
    bondintent.addAction(BluetoothDevice.ACTION_FOUND);//KS add
    registerReceiver(mPairReceiver, bondintent);//KS turn on

    final IntentFilter pairingRequestFilter = new IntentFilter(BluetoothDevice.ACTION_PAIRING_REQUEST);
    pairingRequestFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY - 1);
    registerReceiver(mPairingRequestRecevier, pairingRequestFilter);
}
 
Example 2
Source File: MainActivity.java    From TestChat with Apache License 2.0 6 votes vote down vote up
private void initReceiver() {
        IntentFilter intentFilter = new IntentFilter(Constant.NEW_MESSAGE_ACTION);
//                这里设置优先级要比ChatActivity低,聊天界面一旦接受到消息,这里就不需要再接受
        intentFilter.setPriority(10);
//                聊天消息的监听
        registerReceiver(mReceiver = new NewMessageReceiver(), new IntentFilter(Constant.NEW_MESSAGE_ACTION));
        IntentFilter filter = new IntentFilter();
//                说说消息接受
        filter.addAction(Constant.NEW_SHARE_MESSAGE_ACTION);
//                说说消息改变实时监听
        filter.addAction(Constant.NOTIFY_CHANGE_ACTION);
        registerReceiver(shareReceiver = new ShareMessageReceiver(), filter);
//                网络状态改变监听
        registerReceiver(netWorkReceiver = new NetWorkChangedReceiver(), new IntentFilter(Constant.NETWORK_CONNECTION_CHANGE));
        netWorkReceiver.registerListener(this);
//                单聊和系统推送消息监听
        PushMessageReceiver.registerListener(this);
    }
 
Example 3
Source File: G5CollectionService.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        initScanCallback();
    }
    advertiseTimeMS.add((long)0);

    prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    listenForChangeInSettings(true);

    // TODO check this
    //bgToSpeech = BgToSpeech.setupTTS(getApplicationContext()); //keep reference to not being garbage collected
    // handler = new Handler(getApplicationContext().getMainLooper());

    final IntentFilter bondintent = new IntentFilter(BluetoothDevice.ACTION_BOND_STATE_CHANGED);//KS turn on
    bondintent.addAction(BluetoothDevice.ACTION_FOUND);//KS add
    registerReceiver(mPairReceiver, bondintent);//KS turn on

    final IntentFilter pairingRequestFilter = new IntentFilter(BluetoothDevice.ACTION_PAIRING_REQUEST);
    pairingRequestFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY - 1);
    registerReceiver(mPairingRequestRecevier, pairingRequestFilter);
}
 
Example 4
Source File: PhoneReceiver.java    From android-common with Apache License 2.0 6 votes vote down vote up
/**
 * 去电时:
 * 未接:phone_state=OFFHOOK;
 * 挂断:phone_state=IDLE
 * 来电时:
 * 未接:phone_state=RINGING
 * 已接:phone_state=OFFHOOK;
 * 挂断:phone_state=IDLE
 */
//public void registerCallStateListener(Context context, PhoneStateListener listener) {
//    try {
//        //获取电话通讯服务
//        TelephonyManager tpm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
//        tpm.listen(listener, PhoneStateListener.LISTEN_CALL_STATE);
//    } catch (Exception e) {
//        e.printStackTrace();
//    }
//}
public void registerReceiver(Context context, PhoneListener phoneListener) {
    try {
        IntentFilter filter = new IntentFilter();
        filter.addAction("android.intent.action.PHONE_STATE");
        filter.addAction("android.intent.action.NEW_OUTGOING_CALL");
        filter.setPriority(Integer.MAX_VALUE);
        context.registerReceiver(this, filter);
        this.phoneListener = phoneListener;
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 5
Source File: ChatActivity.java    From Conquer with Apache License 2.0 5 votes vote down vote up
private void initNewMessageBroadCast() {
	// 注册接收消息广播
	receiver = new NewBroadcastReceiver();
	IntentFilter intentFilter = new IntentFilter(BmobConfig.BROADCAST_NEW_MESSAGE);
	// 设置广播的优先级别大于Mainacitivity,这样如果消息来的时候正好在chat页面,直接显示消息,而不是提示消息未读
	intentFilter.setPriority(5);
	registerReceiver(receiver, intentFilter);
}
 
Example 6
Source File: TimeReceiver.java    From zone-sdk with MIT License 5 votes vote down vote up
public void registerReceiver(Context context, TimeListener timeListener) {
    try {
        IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_TIME_CHANGED);
        filter.addAction(Intent.ACTION_TIME_TICK);
        filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
        filter.setPriority(Integer.MAX_VALUE);
        context.registerReceiver(this, filter);
        this.timeListener = timeListener;
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 7
Source File: KeyguardService.java    From AcDisplay with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    final Context context = getContext();
    mPackageName = PackageUtils.getName(context);
    mScreenOff = !PowerUtils.isScreenOn(context);
    // Register base receiver that is watching ACTION_SCREEN_ON,
    // ACTION_SCREEN_OFF and does completely nothing except
    // saving the screen off timestamp.
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_SCREEN_ON);
    intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
    intentFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY - 1); // highest priority
    context.registerReceiver(mScreenReceiver, intentFilter);
}
 
Example 8
Source File: BaseActivity.java    From Viewer with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	TAG = this.getClass().getSimpleName();
	super.onCreate(savedInstanceState);
	userInfo = getSharedPreferences("", MODE_PRIVATE);
	agent_pref = getSharedPreferences("AgentPrefs", 0);
	if(null != savedInstanceState){
		finish();
	}
	IntentFilter filter = new IntentFilter();
	filter.addAction(Constants.CONNECTIVITY_CHANGE_ACTION);
	filter.setPriority(1000);
	registerReceiver(broadReceiver, filter);
}
 
Example 9
Source File: MainTimeLineActivity.java    From iBeebo with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();
    IntentFilter filter = new IntentFilter(AppEventAction.UnRead_Message_Action);
    filter.setPriority(1);


    newMsgInterruptBroadcastReceiver = new NewMsgInterruptBroadcastReceiver();
    Utility.registerReceiverIgnoredReceiverHasRegisteredHereException(this, newMsgInterruptBroadcastReceiver, filter);

    // ensure timeline picture type is correct
    ConnectionChangeReceiver.judgeNetworkStatus(this, false);
}
 
Example 10
Source File: WifiapActivity.java    From WifiChat with GNU General Public License v2.0 5 votes vote down vote up
/** 动态注册广播 */
public void initBroadcast() {
    mWifiapBroadcast = new WifiapBroadcast(this);
    IntentFilter filter = new IntentFilter();
    filter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
    filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
    filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
    filter.setPriority(Integer.MAX_VALUE);
    registerReceiver(mWifiapBroadcast, filter);
}
 
Example 11
Source File: SensorsDumpService.java    From AcDisplay with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onCreate() {
    Context context = getContext();
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_SCREEN_ON);
    intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
    intentFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY - 1);
    context.registerReceiver(mReceiver, intentFilter);

    mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
}
 
Example 12
Source File: CompoundOrderedBroadcastWithResultReceiver.java    From coursera-android with MIT License 5 votes vote down vote up
@Override
protected void onStart() {
    super.onStart();
    IntentFilter intentFilter = new IntentFilter(CUSTOM_INTENT);
    intentFilter.setPriority(3);
    registerReceiver(mReceiver1, intentFilter);
}
 
Example 13
Source File: BuffersActivity.java    From tapchat-android with Apache License 2.0 5 votes vote down vote up
@Override public void onStart() {
    super.onStart();

    IntentFilter pushFilter = new IntentFilter(TapchatApp.ACTION_MESSAGE_NOTIFY);
    pushFilter.setPriority(10);
    registerReceiver(mPushReceiver, pushFilter);

    IntentFilter openFilter = new IntentFilter(TapchatApp.ACTION_OPEN_BUFFER);
    openFilter.setPriority(10);
    registerReceiver(mOpenReceiver, openFilter);
}
 
Example 14
Source File: MainActivity.java    From Hook with Apache License 2.0 5 votes vote down vote up
public void registerMessageReceiver() {
    mMessageReceiver = new MessageReceiver();
    IntentFilter filter = new IntentFilter();
    filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
    filter.addAction(Constans.MESSAGE_RECEIVED_ACTION);
    registerReceiver(mMessageReceiver, filter);
}
 
Example 15
Source File: PhoneReceiver.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 注册电话监听广播
 */
public static void registerReceiver() {
    try {
        IntentFilter filter = new IntentFilter();
        // 电话状态监听
        filter.addAction(PHONE_STATE);
        filter.addAction(NEW_OUTGOING_CALL);
        filter.setPriority(Integer.MAX_VALUE);
        // 注册广播
        AppUtils.registerReceiver(sReceiver, filter);
    } catch (Exception e) {
        LogPrintUtils.eTag(TAG, e, "registerReceiver");
    }
}
 
Example 16
Source File: AppTypeMonitor.java    From Noyze with Apache License 2.0 5 votes vote down vote up
private static IntentFilter getIntentFilter() {
    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_PACKAGE_ADDED);
    filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
    return filter;
}
 
Example 17
Source File: BluetoothGlucoseMeter.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    final IntentFilter pairingRequestFilter = new IntentFilter(BluetoothDevice.ACTION_PAIRING_REQUEST);
    pairingRequestFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY - 1);
    registerReceiver(mPairingRequestRecevier, pairingRequestFilter);
}
 
Example 18
Source File: SmsReceiver.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 注册短信监听广播
 */
public static void registerReceiver() {
    try {
        IntentFilter filter = new IntentFilter();
        // 短信获取监听
        filter.addAction("android.provider.Telephony.SMS_RECEIVED");
        filter.setPriority(Integer.MAX_VALUE);
        // 注册广播
        AppUtils.registerReceiver(sReceiver, filter);
    } catch (Exception e) {
        LogPrintUtils.eTag(TAG, e, "registerReceiver");
    }
}
 
Example 19
Source File: AlarmManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public InteractiveStateReceiver() {
    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    filter.addAction(Intent.ACTION_SCREEN_ON);
    filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
    getContext().registerReceiver(this, filter);
}
 
Example 20
Source File: WifiUtil.java    From ShareBox with Apache License 2.0 4 votes vote down vote up
public static void getNearWifiList(final Context context, final WifiReceiver.IReceiveNewNetWorks listener)
{
    WifiManager manager= (WifiManager) context.getSystemService(Context.WIFI_SERVICE);

    final WifiReceiver receiver=new WifiReceiver(manager);

    WifiReceiver.IReceiveNewNetWorks wListener=new WifiReceiver.IReceiveNewNetWorks() {

        WifiReceiver _receiver=receiver;

        @Override
        public void onReceive(ArrayList<ScanResult> list) {

            listener.onReceive(list);

            if(_receiver!=null)
            {
                try
                {
                    context.unregisterReceiver(_receiver);
                    _receiver=null;
                }catch (Exception e)
                {
                    e.printStackTrace();
                }
            }

        }
    };

    receiver.setReceiveListener(wListener);

    manager.disconnect();

    if(!manager.isWifiEnabled())
      manager.setWifiEnabled(true);

    IntentFilter filter=new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION);

    filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
    context.registerReceiver(receiver,filter);
}