android.content.Context.unregisterReceiver()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(5.2k)|赞(0)|评价(0)|浏览(211)

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

Context.unregisterReceiver介绍

暂无

代码示例

代码示例来源:origin: bumptech/glide

private void unregister() {
 if (!isRegistered) {
  return;
 }
 context.unregisterReceiver(connectivityReceiver);
 isRegistered = false;
}

代码示例来源:origin: google/ExoPlayer

/**
 * Unregisters the receiver, meaning it will no longer notify the listener when audio capability
 * changes occur.
 */
public void unregister() {
 if (receiver != null) {
  context.unregisterReceiver(receiver);
 }
}

代码示例来源:origin: square/picasso

void unregister() {
 dispatcher.context.unregisterReceiver(this);
}

代码示例来源:origin: google/agera

@Override
 public void observableDeactivated() {
  context.unregisterReceiver(broadcastReceiver);
 }
}

代码示例来源:origin: facebook/facebook-android-sdk

private void unregisterBroadcastReceiver() {
  if (broadcastReceiver != null) {
    try {
      context.unregisterReceiver(broadcastReceiver);
    } catch (Exception e) {
      // ignore
    }
    broadcastReceiver = null;
  }
}

代码示例来源:origin: journeyapps/zxing-android-embedded

private void unregisterReceiver() {
  if (registered) {
    context.unregisterReceiver(powerStatusReceiver);
    registered = false;
  }
}

代码示例来源:origin: gotev/android-upload-service

/**
 * Unregister this upload receiver.<br>
 * If you use this receiver in an {@link android.app.Activity}, you have to call this method inside
 * {@link android.app.Activity#onPause()}, after {@code super.onPause();}.<br>
 * If you use it in a {@link android.app.Service}, you have to
 * call this method inside {@link android.app.Service#onDestroy()}.
 *
 * @param context context in which to unregister this receiver
 */
public void unregister(final Context context) {
  context.unregisterReceiver(this);
}

代码示例来源:origin: TeamNewPipe/NewPipe

protected void unregisterBroadcastReceiver() {
  try {
    context.unregisterReceiver(broadcastReceiver);
  } catch (final IllegalArgumentException unregisteredException) {
    Log.w(TAG, "Broadcast receiver already unregistered (" + unregisteredException.getMessage() + ")");
  }
}

代码示例来源:origin: k9mail/k-9

private static void unregisterFileCleanupReceiver(Context context) {
  synchronized (cleanupReceiverMonitor) {
    if (cleanupReceiver == null) {
      return;
    }
    Timber.d("Unregistering temp file cleanup receiver");
    context.unregisterReceiver(cleanupReceiver);
    cleanupReceiver = null;
  }
}

代码示例来源:origin: chentao0707/SimplifyReader

public static void unRegisterNetworkStateReceiver(Context mContext) {
  if (mBroadcastReceiver != null) {
    try {
      mContext.getApplicationContext().unregisterReceiver(mBroadcastReceiver);
    } catch (Exception e) {
      TLog.d(TAG, e.getMessage());
    }
  }
}

代码示例来源:origin: k9mail/k-9

private static void unregisterFileCleanupReceiver(Context context) {
  synchronized (cleanupReceiverMonitor) {
    if (cleanupReceiver == null) {
      return;
    }
    Timber.d("Unregistering temp file cleanup receiver");
    context.unregisterReceiver(cleanupReceiver);
    cleanupReceiver = null;
  }
}

代码示例来源:origin: igniterealtime/Smack

/**
   * Unregister the alarm broadcast receiver and cancel the alarm.
   */
  public static void onDestroy() {
    sContext.unregisterReceiver(ALARM_BROADCAST_RECEIVER);
    sAlarmManager.cancel(sPendingIntent);
  }
}

代码示例来源:origin: seven332/EhViewer

private void unregisterReceiver() {
    getContext().unregisterReceiver(mIntentReceiver);
  }
}

代码示例来源:origin: lipangit/JiaoZiVideoPlayer

public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
      int level = intent.getIntExtra("level", 0);
      int scale = intent.getIntExtra("scale", 100);
      int percent = level * 100 / scale;
      LAST_GET_BATTERYLEVEL_PERCENT = percent;
      setBatteryLevel();
      try {
        getContext().unregisterReceiver(battertReceiver);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
};

代码示例来源:origin: google/ExoPlayer

/** Stops watching for changes. */
public void stop() {
 context.unregisterReceiver(receiver);
 receiver = null;
 if (networkCallback != null) {
  unregisterNetworkCallback();
 }
 logd(this + " stopped");
}

代码示例来源:origin: google/ExoPlayer

private void stopNotification() {
 if (isNotificationStarted) {
  notificationManager.cancel(notificationId);
  isNotificationStarted = false;
  context.unregisterReceiver(notificationBroadcastReceiver);
  if (notificationListener != null) {
   notificationListener.onNotificationCancelled(notificationId);
  }
 }
}

代码示例来源:origin: CarGuo/GSYVideoPlayer

private void unregisterReceiver() {
  if (mConnectivityBroadcastReceiver.isRegistered()) {
    mContext.unregisterReceiver(mConnectivityBroadcastReceiver);
    mConnectivityBroadcastReceiver.setRegistered(false);
  }
}

代码示例来源:origin: alibaba/Tangram-Android

@Override
public void postUnBindView(BaseCell cell) {
  recycleView();
  getContext().unregisterReceiver(mScreenBroadcastReceiver);
}

代码示例来源:origin: square/picasso

@Test public void shutdownUnregistersReceiver() {
 dispatcher.shutdown();
 verify(context).unregisterReceiver(dispatcher.receiver);
}

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

@Test public void shouldHandleErrorWhileTryingToUnregisterReceiver() {
  // given
  strategy.observeNetworkConnectivity(context);
  final RuntimeException exception = new RuntimeException();
  doThrow(exception).when(contextMock).unregisterReceiver(any(BroadcastReceiver.class));

  // when
  strategy.tryToUnregisterReceiver(contextMock);

  // then
  verify(strategy).onError(MarshmallowNetworkObservingStrategy.ERROR_MSG_RECEIVER, exception);
 }
}

相关文章

Context类方法