當前位置: 首頁>>代碼示例>>Java>>正文


Java BroadcastReceiver.onReceive方法代碼示例

本文整理匯總了Java中android.content.BroadcastReceiver.onReceive方法的典型用法代碼示例。如果您正苦於以下問題:Java BroadcastReceiver.onReceive方法的具體用法?Java BroadcastReceiver.onReceive怎麽用?Java BroadcastReceiver.onReceive使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.content.BroadcastReceiver的用法示例。


在下文中一共展示了BroadcastReceiver.onReceive方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: handleReceiver

import android.content.BroadcastReceiver; //導入方法依賴的package包/類
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());
        receiver.onReceive(receiverContext, data.intent);
        if (mirror.android.content.BroadcastReceiver.getPendingResult.call(receiver) != null) {
            result.finish();
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(
                "Unable to start receiver " + data.component
                        + ": " + e.toString(), e);
    }
    VActivityManager.get().broadcastFinish(data.resultData);
}
 
開發者ID:7763sea,項目名稱:VirtualHook,代碼行數:25,代碼來源:VClientImpl.java

示例2: handleReceiver

import android.content.BroadcastReceiver; //導入方法依賴的package包/類
private void handleReceiver(ReceiverData data) {
    BroadcastReceiver.PendingResult result = data.resultData.build();
    try {
        Context context = createPackageContext(data.component.getPackageName());
        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());
        receiver.onReceive(receiverContext, data.intent);
        if (mirror.android.content.BroadcastReceiver.getPendingResult.call(receiver) != null) {
            result.finish();
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(
                "Unable to start receiver " + data.component
                        + ": " + e.toString(), e);
    }
    VActivityManager.get().broadcastFinish(data.resultData);
}
 
開發者ID:codehz,項目名稱:container,代碼行數:22,代碼來源:VClientImpl.java

示例3: testGetTokenCallbackWithIntent

import android.content.BroadcastReceiver; //導入方法依賴的package包/類
/**
 * Tests the behavior of {@link HttpNegotiateAuthenticator.GetTokenCallback} when the result it
 * receives contains an intent rather than a token directly.
 */
@Test
public void testGetTokenCallbackWithIntent() {
    String type = "Dummy_Account";
    HttpNegotiateAuthenticator authenticator = createWithoutNative(type);
    RequestData requestData = new RequestData();
    requestData.nativeResultObject = 42;
    requestData.authTokenType = "foo";
    requestData.account = new Account("a", type);
    requestData.accountManager = sMockAccountManager;
    Bundle b = new Bundle();
    b.putParcelable(AccountManager.KEY_INTENT, new Intent());

    authenticator.new GetTokenCallback(requestData).run(makeFuture(b));
    verifyZeroInteractions(sMockAccountManager);

    // Verify that the broadcast receiver is registered
    Intent intent = new Intent(AccountManager.LOGIN_ACCOUNTS_CHANGED_ACTION);
    ShadowApplication shadowApplication = Robolectric.getShadowApplication();
    List<BroadcastReceiver> receivers = shadowApplication.getReceiversForIntent(intent);
    assertThat("There is one registered broadcast receiver", receivers.size(), equalTo(1));

    // Send the intent to the receiver.
    BroadcastReceiver receiver = receivers.get(0);
    receiver.onReceive(Robolectric.getShadowApplication().getApplicationContext(), intent);

    // Verify that the auth token is properly requested from the account manager.
    verify(sMockAccountManager).getAuthToken(
            eq(new Account("a", type)),
            eq("foo"),
            isNull(Bundle.class),
            eq(true),
            any(HttpNegotiateAuthenticator.GetTokenCallback.class),
            any(Handler.class));
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:39,代碼來源:HttpNegotiateAuthenticatorTest.java

示例4: handleReceiver

import android.content.BroadcastReceiver; //導入方法依賴的package包/類
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) {
        e.printStackTrace();
        throw new RuntimeException(
                "Unable to start receiver " + data.component
                        + ": " + e.toString(), e);
    }
    VActivityManager.get().broadcastFinish(data.resultData);
}
 
開發者ID:coding-dream,項目名稱:TPlayer,代碼行數:28,代碼來源:VClientImpl.java

示例5: broadcastReceiverShouldReceiveAnIntentWhereAirplaneModeIsOff

import android.content.BroadcastReceiver; //導入方法依賴的package包/類
@Test public void broadcastReceiverShouldReceiveAnIntentWhereAirplaneModeIsOff() {
  // given
  final ObservableEmitter<Boolean> emitter = mock(ObservableEmitter.class);
  final BroadcastReceiver receiver = reactiveAirplaneMode.createBroadcastReceiver(emitter);
  final Intent intent = mock(Intent.class);
  when(intent.getBooleanExtra(ReactiveAirplaneMode.INTENT_EXTRA_STATE, false)).thenReturn(false);

  // when
  receiver.onReceive(context, intent);

  // then
  verify(emitter).onNext(false);
}
 
開發者ID:pwittchen,項目名稱:ReactiveAirplaneMode,代碼行數:14,代碼來源:ReactiveAirplaneModeTest.java

示例6: broadcastReceiverShouldReceiveAnIntentWhereAirplaneModeIsOn

import android.content.BroadcastReceiver; //導入方法依賴的package包/類
@Test public void broadcastReceiverShouldReceiveAnIntentWhereAirplaneModeIsOn() {
  // given
  final ObservableEmitter<Boolean> emitter = mock(ObservableEmitter.class);
  final BroadcastReceiver receiver = reactiveAirplaneMode.createBroadcastReceiver(emitter);
  final Intent intent = mock(Intent.class);
  when(intent.getBooleanExtra(ReactiveAirplaneMode.INTENT_EXTRA_STATE, false)).thenReturn(true);

  // when
  receiver.onReceive(context, intent);

  // then
  verify(emitter).onNext(true);
}
 
開發者ID:pwittchen,項目名稱:ReactiveAirplaneMode,代碼行數:14,代碼來源:ReactiveAirplaneModeTest.java

示例7: proceedBroadcast

import android.content.BroadcastReceiver; //導入方法依賴的package包/類
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);
}
 
開發者ID:oasisfeng,項目名稱:condom,代碼行數:6,代碼來源:CondomCore.java


注:本文中的android.content.BroadcastReceiver.onReceive方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。