本文整理了Java中android.content.Context.registerReceiver()
方法的一些代码示例,展示了Context.registerReceiver()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context.registerReceiver()
方法的具体详情如下:
包路径:android.content.Context
类名称:Context
方法名:registerReceiver
暂无
代码示例来源:origin: google/agera
@Override
public void observableActivated() {
context.registerReceiver(broadcastReceiver, filter);
}
代码示例来源:origin: square/picasso
void register() {
IntentFilter filter = new IntentFilter();
filter.addAction(ACTION_AIRPLANE_MODE_CHANGED);
if (dispatcher.scansNetworkChanges) {
filter.addAction(CONNECTIVITY_ACTION);
}
dispatcher.context.registerReceiver(this, filter);
}
代码示例来源:origin: stackoverflow.com
public class PowerUtil {
public static boolean isConnected(Context context) {
Intent intent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
return plugged == BatteryManager.BATTERY_PLUGGED_AC || plugged == BatteryManager.BATTERY_PLUGGED_USB;
}
}
代码示例来源:origin: journeyapps/zxing-android-embedded
private void registerReceiver() {
if (!registered) {
context.registerReceiver(powerStatusReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
registered = true;
}
}
代码示例来源:origin: yigit/android-priority-jobqueue
@TargetApi(23)
private void listenForIdle(Context context) {
context.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
dispatchNetworkChange(context);
}
}, new IntentFilter(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED));
}
代码示例来源:origin: google/ExoPlayer
/**
* Returns the current audio capabilities for the device.
*
* @param context A context for obtaining the current audio capabilities.
* @return The current audio capabilities for the device.
*/
@SuppressWarnings("InlinedApi")
public static AudioCapabilities getCapabilities(Context context) {
return getCapabilities(
context.registerReceiver(null, new IntentFilter(AudioManager.ACTION_HDMI_AUDIO_PLUG)));
}
代码示例来源:origin: google/ExoPlayer
private boolean checkChargingRequirement(Context context) {
if (!isChargingRequired()) {
return true;
}
Intent batteryStatus =
context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
if (batteryStatus == null) {
return false;
}
int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
return status == BatteryManager.BATTERY_STATUS_CHARGING
|| status == BatteryManager.BATTERY_STATUS_FULL;
}
代码示例来源:origin: bumptech/glide
private void register() {
if (isRegistered) {
return;
}
// Initialize isConnected.
isConnected = isConnected(context);
try {
// See #1405
context.registerReceiver(connectivityReceiver,
new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
isRegistered = true;
} catch (SecurityException e) {
// See #1417, registering the receiver can throw SecurityException.
if (Log.isLoggable(TAG, Log.WARN)) {
Log.w(TAG, "Failed to register", e);
}
}
}
代码示例来源:origin: CarGuo/GSYVideoPlayer
private void registerReceiver() {
IntentFilter filter = new IntentFilter();
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
mContext.registerReceiver(mConnectivityBroadcastReceiver, filter);
mConnectivityBroadcastReceiver.setRegistered(true);
}
代码示例来源:origin: CarGuo/GSYVideoPlayer
FloatLifecycle(Context applicationContext, boolean showFlag, Class[] activities, LifecycleListener lifecycleListener) {
this.showFlag = showFlag;
this.activities = activities;
mLifecycleListener = lifecycleListener;
mHandler = new Handler();
((Application) applicationContext).registerActivityLifecycleCallbacks(this);
applicationContext.registerReceiver(this, new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
}
代码示例来源:origin: TeamNewPipe/NewPipe
protected void registerBroadcastReceiver() {
// Try to unregister current first
unregisterBroadcastReceiver();
context.registerReceiver(broadcastReceiver, intentFilter);
}
代码示例来源:origin: chentao0707/SimplifyReader
public static void registerNetworkStateReceiver(Context mContext) {
IntentFilter filter = new IntentFilter();
filter.addAction(CUSTOM_ANDROID_NET_CHANGE_ACTION);
filter.addAction(ANDROID_NET_CHANGE_ACTION);
mContext.getApplicationContext().registerReceiver(getReceiver(), filter);
}
代码示例来源:origin: stackoverflow.com
IntentFilter intentFilter = new IntentFilter("android.intent.action.AIRPLANE_MODE");
BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.d("AirplaneMode", "Service state changed");
}
};
context.registerReceiver(receiver, intentFilter);
代码示例来源:origin: lipangit/JiaoZiVideoPlayer
public void setSystemTimeAndBattery() {
SimpleDateFormat dateFormater = new SimpleDateFormat("HH:mm");
Date date = new Date();
videoCurrentTime.setText(dateFormater.format(date));
if ((System.currentTimeMillis() - LAST_GET_BATTERYLEVEL_TIME) > 30000) {
LAST_GET_BATTERYLEVEL_TIME = System.currentTimeMillis();
getContext().registerReceiver(
battertReceiver,
new IntentFilter(Intent.ACTION_BATTERY_CHANGED)
);
} else {
setBatteryLevel();
}
}
代码示例来源:origin: k9mail/k-9
private static void registerFileCleanupReceiver(Context context) {
synchronized (cleanupReceiverMonitor) {
if (cleanupReceiver != null) {
return;
}
Timber.d("Registering temp file cleanup receiver");
cleanupReceiver = new DecryptedFileProviderCleanupReceiver();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
context.registerReceiver(cleanupReceiver, intentFilter);
}
}
代码示例来源:origin: facebook/facebook-android-sdk
private void registerBroadcastReceiver() {
if (broadcastReceiver != null) {
unregisterBroadcastReceiver();
}
broadcastReceiver = new ScanResultBroadcastReceiver();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
context.registerReceiver(broadcastReceiver, intentFilter);
}
代码示例来源:origin: seven332/EhViewer
private void registerReceiver() {
final IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_TIME_TICK);
filter.addAction(Intent.ACTION_TIME_CHANGED);
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
getContext().registerReceiver(mIntentReceiver, filter, null, getHandler());
}
代码示例来源:origin: google/ExoPlayer
private void startOrUpdateNotification() {
if (player != null) {
Notification notification = updateNotification(null);
if (!isNotificationStarted) {
isNotificationStarted = true;
context.registerReceiver(notificationBroadcastReceiver, intentFilter);
if (notificationListener != null) {
notificationListener.onNotificationStarted(notificationId, notification);
}
}
}
}
代码示例来源:origin: k9mail/k-9
private static void registerFileCleanupReceiver(Context context) {
synchronized (cleanupReceiverMonitor) {
if (cleanupReceiver != null) {
return;
}
Timber.d("Registering temp file cleanup receiver");
cleanupReceiver = new AttachmentTempFileProviderCleanupReceiver();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
context.registerReceiver(cleanupReceiver, intentFilter);
}
}
代码示例来源:origin: seven332/EhViewer
private void registerReceiver() {
final IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_BATTERY_CHANGED);
getContext().registerReceiver(mIntentReceiver, filter, null, getHandler());
}
内容来源于网络,如有侵权,请联系作者删除!