When a broadcast receiver is registered with the registerReceiver() method, the method returns an Intent object or null indicating whether the registration was successful. If the method returns null, no broadcast sink matching the given IntentFilter was found. Otherwise, it returns the Intent object of the first matching broadcast receiver.
// 创建BroadcastReceiver对象
BroadcastReceiver receiver = new MyBroadcastReceiver();
// 创建IntentFilter对象
IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
// 注册广播接收器
Intent intent = registerReceiver(receiver, filter);
if (intent == null) {
// 广播接收器注册失败
Log.e(TAG, "Failed to register BroadcastReceiver");
} else {
// 广播接收器注册成功
Log.d(TAG, "BroadcastReceiver registered successfully");
}