android.content.BroadcastReceiver类的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(240)

本文整理了Java中android.content.BroadcastReceiver类的一些代码示例,展示了BroadcastReceiver类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BroadcastReceiver类的具体详情如下:
包路径:android.content.BroadcastReceiver
类名称:BroadcastReceiver

BroadcastReceiver介绍

暂无

代码示例

代码示例来源:origin: robolectric/robolectric

@Override
 public void run() {
  receiver.onReceive(RuntimeEnvironment.application, broadcastIntent);
 }
});

代码示例来源:origin: robolectric/robolectric

public void onReceive(Context context, Intent intent, AtomicBoolean abort) {
  this.abort = abort;
  onReceive(context, intent);
  // If the underlying receiver has called goAsync(), we should not finish the pending result yet - they'll do that
  // for us.
  if (receiver.getPendingResult() != null) {
   receiver.getPendingResult().finish();
  }
 }
}

代码示例来源:origin: robolectric/robolectric

private Intent processStickyIntents(
  IntentFilter filter, BroadcastReceiver receiver, Context context) {
 Intent result = null;
 for (Intent stickyIntent : stickyIntents.values()) {
  if (filter.matchAction(stickyIntent.getAction())) {
   if (result == null) {
    result = stickyIntent;
   }
   if (receiver != null) {
    receiver.setPendingResult(ShadowBroadcastPendingResult.createSticky(stickyIntent));
    receiver.onReceive(context, stickyIntent);
    receiver.setPendingResult(null);
   } else if (result != null) {
    break;
   }
  }
 }
 return result;
}

代码示例来源:origin: robolectric/robolectric

@Override
 public void run() {
  receiver.setPendingResult(ShadowBroadcastPendingResult.create(0, null, null, false));
  shReceiver.onReceive(context, broadcastIntent, abort);
 }
});

代码示例来源:origin: cantrowitz/RxBroadcast

/**
 * Calls {@link BroadcastReceiver#abortBroadcast()}
 */
public void abortBroadcast() {
  broadcastReceiver.abortBroadcast();
}

代码示例来源:origin: robolectric/robolectric

@Override
 public ListenableFuture<BroadcastResultHolder> apply(
   BroadcastResultHolder broadcastResultHolder) throws Exception {
  final BroadcastReceiver.PendingResult result =
    ShadowBroadcastPendingResult.create(
      broadcastResultHolder.resultCode,
      broadcastResultHolder.resultData,
      broadcastResultHolder.resultExtras,
      true /*ordered */);
  wrapper.broadcastReceiver.setPendingResult(result);
  scheduler.post(
    () -> {
     ShadowBroadcastReceiver shadowBroadcastReceiver =
       Shadow.extract(wrapper.broadcastReceiver);
     shadowBroadcastReceiver.onReceive(context, intent, abort);
    });
  return BroadcastResultHolder.transform(result);
 }
},

代码示例来源:origin: jamorham/xDrip-plus

device.setPin(convertPinToBytes(pinHint));
Log.d(TAG, "Setting pairing pin to " + pinHint);
broadcastReceiver.abortBroadcast();
  device.setPairingConfirmation(true);
  JoH.static_toast_short("xDrip Pairing");
  broadcastReceiver.abortBroadcast();
} else {
  Log.d(TAG, "Attempting to passthrough PIN pairing");

代码示例来源:origin: robolectric/robolectric

@Implementation
protected void onReceive(Context context, Intent intent) {
 if (abort == null || !abort.get()) {
  receiver.onReceive(context, intent);
 }
}

代码示例来源:origin: org.robolectric/shadows-framework

private Intent processStickyIntents(
  IntentFilter filter, BroadcastReceiver receiver, Context context) {
 Intent result = null;
 for (Intent stickyIntent : stickyIntents.values()) {
  if (filter.matchAction(stickyIntent.getAction())) {
   if (result == null) {
    result = stickyIntent;
   }
   if (receiver != null) {
    receiver.setPendingResult(ShadowBroadcastPendingResult.createSticky(stickyIntent));
    receiver.onReceive(context, stickyIntent);
    receiver.setPendingResult(null);
   } else if (result != null) {
    break;
   }
  }
 }
 return result;
}

代码示例来源:origin: org.robolectric/shadows-core

@Override
public ListenableFuture<BroadcastResultHolder> apply(BroadcastResultHolder broadcastResultHolder) throws Exception {
 final BroadcastReceiver.PendingResult result = ShadowBroadcastPendingResult.create(
     broadcastResultHolder.resultCode,
     broadcastResultHolder.resultData,
     broadcastResultHolder.resultExtras,
     true /*ordered */);
 wrapper.broadcastReceiver.setPendingResult(result);
 scheduler.post(new Runnable() {
  @Override
  public void run() {
   Shadows.shadowOf(wrapper.broadcastReceiver).onReceive(realApplication, intent, abort);
  }
 });
 return BroadcastResultHolder.transform(result);
}

代码示例来源:origin: org.robolectric/framework

public void onReceive(Context context, Intent intent, AtomicBoolean abort) {
  this.abort = abort;
  onReceive(context, intent);
  // If the underlying receiver has called goAsync(), we should not finish the pending result yet - they'll do that
  // for us.
  if (receiver.getPendingResult() != null) {
   receiver.getPendingResult().finish();
  }
 }
}

代码示例来源:origin: jamorham/xDrip-plus

device.setPin(convertPinToBytes(pinHint));
Log.d(TAG, "Setting pairing pin to " + pinHint);
broadcastReceiver.abortBroadcast();
  device.setPairingConfirmation(true);
  JoH.static_toast_short("xDrip Pairing");
  broadcastReceiver.abortBroadcast();
} else {
  Log.d(TAG, "Attempting to passthrough PIN pairing");

代码示例来源:origin: oasisfeng/condom

void proceedBroadcast(final Context context, final Intent intent, final WrappedValueProcedure<Boolean> procedure,
           final @Nullable BroadcastReceiver resultReceiver) {
  if (proceed(OutboundType.BROADCAST, intent, Boolean.FALSE, procedure) == Boolean.FALSE && resultReceiver != null)
    resultReceiver.onReceive(new ReceiverRestrictedContext(context), intent);
}

代码示例来源:origin: org.robolectric/framework

@Override
public ListenableFuture<BroadcastResultHolder> apply(BroadcastResultHolder broadcastResultHolder) throws Exception {
 final BroadcastReceiver.PendingResult result = ShadowBroadcastPendingResult.create(
     broadcastResultHolder.resultCode,
     broadcastResultHolder.resultData,
     broadcastResultHolder.resultExtras,
     true /*ordered */);
 wrapper.broadcastReceiver.setPendingResult(result);
 scheduler.post(new Runnable() {
  @Override
  public void run() {
   Shadows.shadowOf(wrapper.broadcastReceiver).onReceive(realApplication, intent, abort);
  }
 });
 return BroadcastResultHolder.transform(result);
}

代码示例来源:origin: org.robolectric/shadows-framework

public void onReceive(Context context, Intent intent, AtomicBoolean abort) {
  this.abort = abort;
  onReceive(context, intent);
  // If the underlying receiver has called goAsync(), we should not finish the pending result yet - they'll do that
  // for us.
  if (receiver.getPendingResult() != null) {
   receiver.getPendingResult().finish();
  }
 }
}

代码示例来源:origin: NightscoutFoundation/xDrip

device.setPin(convertPinToBytes(pinHint));
Log.d(TAG, "Setting pairing pin to " + pinHint);
broadcastReceiver.abortBroadcast();
  device.setPairingConfirmation(true);
  JoH.static_toast_short("xDrip Pairing");
  broadcastReceiver.abortBroadcast();
} else {
  Log.d(TAG, "Attempting to passthrough PIN pairing");

代码示例来源:origin: android-hacker/VirtualXposed

private void handleReceiver(ReceiverData data) {
  BroadcastReceiver.PendingResult result = data.resultData.build();
  try {
    if (!isBound()) {
      bindApplication(data.component.getPackageName(), data.processName);
    }
    Context context = mInitialApplication.getBaseContext();
    Context receiverContext = ContextImpl.getReceiverRestrictedContext.call(context);
    String className = data.component.getClassName();
    BroadcastReceiver receiver = (BroadcastReceiver) context.getClassLoader().loadClass(className).newInstance();
    mirror.android.content.BroadcastReceiver.setPendingResult.call(receiver, result);
    data.intent.setExtrasClassLoader(context.getClassLoader());
    if (data.intent.getComponent() == null) {
      data.intent.setComponent(data.component);
    }
    receiver.onReceive(receiverContext, data.intent);
    if (mirror.android.content.BroadcastReceiver.getPendingResult.call(receiver) != null) {
      result.finish();
    }
  } catch (Exception e) {
    // must be this for misjudge of anti-virus!!
    throw new RuntimeException(String.format("Unable to start receiver: %s ", data.component), e);
  }
  VActivityManager.get().broadcastFinish(data.resultData);
}

代码示例来源:origin: org.robolectric/shadows-core-v23

@Override
public ListenableFuture<BroadcastResultHolder> apply(BroadcastResultHolder broadcastResultHolder) throws Exception {
 final BroadcastReceiver.PendingResult result = ShadowBroadcastPendingResult.create(
     broadcastResultHolder.resultCode,
     broadcastResultHolder.resultData,
     broadcastResultHolder.resultExtras,
     true /*ordered */);
 wrapper.broadcastReceiver.setPendingResult(result);
 scheduler.post(new Runnable() {
  @Override
  public void run() {
   Shadows.shadowOf(wrapper.broadcastReceiver).onReceive(realApplication, intent, abort);
  }
 });
 return BroadcastResultHolder.transform(result);
}

代码示例来源:origin: org.robolectric/shadows-core

public void onReceive(Context context, Intent intent, AtomicBoolean abort) {
  this.abort = abort;
  onReceive(context, intent);
  // If the underlying receiver has called goAsync(), we should not finish the pending result yet - they'll do that
  // for us.
  if (receiver.getPendingResult() != null) {
   receiver.getPendingResult().finish();
  }
 }
}

代码示例来源:origin: pwittchen/ReactiveNetwork

@Test public void shouldReceiveIntentInIdleMode() {
 // given
 preparePowerManagerMocks(Boolean.TRUE, Boolean.FALSE);
 BroadcastReceiver broadcastReceiver = strategy.createIdleBroadcastReceiver();
 // when
 broadcastReceiver.onReceive(contextMock, intent);
 // then
 verify(strategy).onNext(any(Connectivity.class));
}

相关文章