ContextExtensions.kt 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * Nextcloud Android client application
  3. *
  4. * @author Alper Ozturk
  5. * Copyright (C) 2023 Alper Ozturk
  6. * Copyright (C) 2023 Nextcloud GmbH
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. package com.nextcloud.utils.extensions
  22. import android.annotation.SuppressLint
  23. import android.content.BroadcastReceiver
  24. import android.content.Context
  25. import android.content.Intent
  26. import android.content.IntentFilter
  27. import android.os.Build
  28. import com.owncloud.android.datamodel.ReceiverFlag
  29. @SuppressLint("UnspecifiedRegisterReceiverFlag")
  30. fun Context.registerBroadcastReceiver(receiver: BroadcastReceiver?, filter: IntentFilter, flag: ReceiverFlag): Intent? {
  31. return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
  32. registerReceiver(receiver, filter, flag.getId())
  33. } else {
  34. registerReceiver(receiver, filter)
  35. }
  36. }