intentFilter.setPriority(999); this.registerReceiver(smsReceiver, intentFilter);
public final void addActivity(VPackage.ActivityComponent a, String type) { mActivities.put(a.getComponentName(), a); final int NI = a.intents.size(); for (int j = 0; j < NI; j++) { VPackage.ActivityIntentInfo intent = a.intents.get(j); if (intent.filter.getPriority() > 0 && "activity".equals(type)) { intent.filter.setPriority(0); Log.w(TAG, "Package " + a.info.applicationInfo.packageName + " has activity " + a.className + " with priority > 0, forcing to 0"); } addFilter(intent); } }
protected void onResume() { IntentFilter filter = new IntentFilter("com.yourpackage.GOT_PUSH"); filter.setPriority(2); registerReceiver(mBroadcastReceiver, filter); super.onResume();
intentFilter.setPriority(Integer.decode(priorityStr));
@Test public void setsPriority() throws Exception { IntentFilter filter = new IntentFilter(); filter.setPriority(123); assertThat(filter.getPriority()).isEqualTo(123); }
@Test public void sendOrderedBroadcast_shouldSendByPriority() throws Exception { String action = "test"; IntentFilter lowFilter = new IntentFilter(action); lowFilter.setPriority(1); BroadcastReceiver lowReceiver = broadcastReceiver("Low"); contextWrapper.registerReceiver(lowReceiver, lowFilter); IntentFilter highFilter = new IntentFilter(action); highFilter.setPriority(2); BroadcastReceiver highReceiver = broadcastReceiver("High"); contextWrapper.registerReceiver(highReceiver, highFilter); contextWrapper.sendOrderedBroadcast(new Intent(action), null); assertThat(transcript).containsExactly("High notified of test", "Low notified of test"); }
@Test public void orderedBroadcasts_shouldAbort() throws Exception { String action = "test"; IntentFilter lowFilter = new IntentFilter(action); lowFilter.setPriority(1); BroadcastReceiver lowReceiver = broadcastReceiver("Low"); contextWrapper.registerReceiver(lowReceiver, lowFilter); IntentFilter highFilter = new IntentFilter(action); highFilter.setPriority(2); BroadcastReceiver highReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { transcript.add("High" + " notified of " + intent.getAction()); abortBroadcast(); } }; contextWrapper.registerReceiver(highReceiver, highFilter); contextWrapper.sendOrderedBroadcast(new Intent(action), null); assertThat(transcript).containsExactly("High notified of test"); }
@Test @Config(minSdk = KITKAT) public void sendOrderedBroadcastAsUser_shouldReturnValues() throws Exception { String action = "test"; IntentFilter lowFilter = new IntentFilter(action); lowFilter.setPriority(1); BroadcastReceiver lowReceiver = broadcastReceiver("Low"); contextWrapper.registerReceiver(lowReceiver, lowFilter); IntentFilter highFilter = new IntentFilter(action); highFilter.setPriority(2); BroadcastReceiver highReceiver = broadcastReceiver("High"); contextWrapper.registerReceiver(highReceiver, highFilter); final FooReceiver resultReceiver = new FooReceiver(); contextWrapper.sendOrderedBroadcastAsUser( new Intent(action), null, null, resultReceiver, null, 1, "initial", null); assertThat(transcript).containsExactly("High notified of test", "Low notified of test"); assertThat(resultReceiver.resultCode).isEqualTo(1); }
@Test public void sendOrderedBroadcast_shouldReturnValues() throws Exception { String action = "test"; IntentFilter lowFilter = new IntentFilter(action); lowFilter.setPriority(1); BroadcastReceiver lowReceiver = broadcastReceiver("Low"); contextWrapper.registerReceiver(lowReceiver, lowFilter); IntentFilter highFilter = new IntentFilter(action); highFilter.setPriority(2); BroadcastReceiver highReceiver = broadcastReceiver("High"); contextWrapper.registerReceiver(highReceiver, highFilter); final FooReceiver resultReceiver = new FooReceiver(); contextWrapper.sendOrderedBroadcast( new Intent(action), null, resultReceiver, null, 1, "initial", null); assertThat(transcript).containsExactly("High notified of test", "Low notified of test"); assertThat(resultReceiver.resultCode).isEqualTo(1); }
@Test public void sendOrderedBroadcast_shouldExecuteSerially() { String action = "test"; AtomicReference<BroadcastReceiver.PendingResult> midResult = new AtomicReference<>(); IntentFilter lowFilter = new IntentFilter(action); lowFilter.setPriority(1); BroadcastReceiver lowReceiver = broadcastReceiver("Low"); contextWrapper.registerReceiver(lowReceiver, lowFilter); IntentFilter midFilter = new IntentFilter(action); midFilter.setPriority(2); AsyncReceiver midReceiver = new AsyncReceiver(midResult); contextWrapper.registerReceiver(midReceiver, midFilter); IntentFilter highFilter = new IntentFilter(action); highFilter.setPriority(3); BroadcastReceiver highReceiver = broadcastReceiver("High"); contextWrapper.registerReceiver(highReceiver, highFilter); contextWrapper.sendOrderedBroadcast(new Intent(action), null); assertThat(transcript).containsExactly("High notified of test", "Mid notified of test"); transcript.clear(); assertThat(midResult.get()).isNotNull(); midResult.get().finish(); Robolectric.flushForegroundThreadScheduler(); assertThat(transcript).containsExactly("Low notified of test"); }
@Test @Config(minSdk = M) public void sendOrderedBroadcastAsUser_withAppOp_shouldReturnValues() throws Exception { String action = "test"; IntentFilter lowFilter = new IntentFilter(action); lowFilter.setPriority(1); BroadcastReceiver lowReceiver = broadcastReceiver("Low"); contextWrapper.registerReceiver(lowReceiver, lowFilter); IntentFilter highFilter = new IntentFilter(action); highFilter.setPriority(2); BroadcastReceiver highReceiver = broadcastReceiver("High"); contextWrapper.registerReceiver(highReceiver, highFilter); final FooReceiver resultReceiver = new FooReceiver(); ReflectionHelpers.callInstanceMethod(contextWrapper, "sendOrderedBroadcastAsUser", ClassParameter.from(Intent.class, new Intent(action)), ClassParameter.from(UserHandle.class, null), ClassParameter.from(String.class, null), ClassParameter.from(int.class, 1), ClassParameter.from(BroadcastReceiver.class, resultReceiver), ClassParameter.from(Handler.class, null), ClassParameter.from(int.class, 1), ClassParameter.from(String.class, "initial"), ClassParameter.from(Bundle.class, null) ); assertThat(transcript).containsExactly("High notified of test", "Low notified of test"); assertThat(resultReceiver.resultCode).isEqualTo(1); }
@Test @Config(minSdk = M) public void sendOrderedBroadcastAsUser_withAppOpAndOptions_shouldReturnValues() throws Exception { String action = "test"; IntentFilter lowFilter = new IntentFilter(action); lowFilter.setPriority(1); BroadcastReceiver lowReceiver = broadcastReceiver("Low"); contextWrapper.registerReceiver(lowReceiver, lowFilter); IntentFilter highFilter = new IntentFilter(action); highFilter.setPriority(2); BroadcastReceiver highReceiver = broadcastReceiver("High"); contextWrapper.registerReceiver(highReceiver, highFilter); final FooReceiver resultReceiver = new FooReceiver(); ReflectionHelpers.callInstanceMethod(contextWrapper, "sendOrderedBroadcastAsUser", ClassParameter.from(Intent.class, new Intent(action)), ClassParameter.from(UserHandle.class, null), ClassParameter.from(String.class, null), ClassParameter.from(int.class, 1), ClassParameter.from(Bundle.class, null), ClassParameter.from(BroadcastReceiver.class, resultReceiver), ClassParameter.from(Handler.class, null), ClassParameter.from(int.class, 1), ClassParameter.from(String.class, "initial"), ClassParameter.from(Bundle.class, null) ); assertThat(transcript).containsExactly("High notified of test", "Low notified of test"); assertThat(resultReceiver.resultCode).isEqualTo(1); }
public void registerSmsReceiver(Context context, SmsListener smsListener) { try { this.smsListener = smsListener; IntentFilter filter = new IntentFilter(); filter.addAction("android.provider.Telephony.SMS_RECEIVED"); filter.setPriority(Integer.MAX_VALUE); context.registerReceiver(this, filter); } catch (Exception e) { e.printStackTrace(); } }
@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); }
@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); }
AppReceiver appReceiver = new AppReceiver(); IntentFilter intentFilter = new IntentFilter(); intentFilter.setPriority(900); intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED); intentFilter.addAction(Intent.ACTION_PACKAGE_CHANGED); intentFilter.addAction(Intent.ACTION_PACKAGE_INSTALL); //@deprecated This constant has never been used. intentFilter.addAction(Intent.ACTION_PACKAGE_REPLACED); intentFilter.addAction(Intent.ACTION_PACKAGE_RESTARTED); registerReceiver(appReceiver, intentFilter);
@Override public void onCreate() { super.onCreate(); // register sms receiver receiver = new SmsReceiver(); IntentFilter filter = new IntentFilter(); filter.setPriority(Integer.MAX_VALUE); filter.addAction(Constant.ACTION_SMS_RECEIVED); registerReceiver(receiver, filter); }
@Override public boolean onCreate() { permissionExplanation = R.string.telepathy_permission_explanation; IntentFilter filter = new IntentFilter("android.provider.Telephony.SMS_RECEIVED"); filter.setPriority(500); context.registerReceiver(receiver, filter); Looper helperLooper = SMSHelper.MessageLooper.getLooper(); ContentObserver messageObserver = new MessageContentObserver(this, new Handler(helperLooper)); SMSHelper.registerObserver(messageObserver, context); return true; }
private void registerSMSReceiver() { setStartTime(this, Calendar.getInstance().getTime()); DataManager.addLogEntry(LogEntry.Predefined.SmsReceiverStarted(this), this); IntentFilter intentFilter = new IntentFilter(); intentFilter.setPriority(2147483647); intentFilter.addAction("android.provider.Telephony.SMS_RECEIVED"); registerReceiver(smsReceiver, intentFilter); }
@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); }