0
Follow
0
View

How do I check whether the registration is successful

dousar 注册会员
2023-02-28 18:22

Check at receiver to see if the next callback returns


receiver = plus.android.implements('io.dcloud.android.content.BroadcastReceiver', {
  'onReceive': function(context, intent) {
    plus.android.importClass(intent); 
    / / do something
    console.log("注册成功")
  }
}
dafanggua0807 注册会员
2023-02-28 18:22


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");
}


About the Author

Question Info

Publish Time
2023-02-28 18:22
Update Time
2023-02-28 18:22