“registerReceiver error hint: 必须是一个或多个类型之一”

huangapple go评论86阅读模式
英文:

registerReceiver error hint " Must be one or more of type"

问题

使用以下代码:

ContextCompat.registerReceiver(this, mIntentReceiver, filter, ContextCompat.RECEIVER_EXPORTED);

或者

registerReceiver(mIntentReceiver, filter, Context.RECEIVER_EXPORTED);

它提示“必须是以下一个或多个:androidx.core.content.ContextCompat.RECEIVER_VISIBLE_TO_INSTANT_APPS,androidx.core.content.ContextCompat.RECEIVER_EXPORTED,androidx.core.content.ContextCompat.RECEIVER_NOT_EXPORTED”。

看起来我没有满足这个选项接口。它提供了更改为RECEIVER_VISIBLE_TO_INSTANT_APPS的提示,如果我采用它,错误将消失。但这并不是完美的选项。

英文:

using
ContextCompat.registerReceiver(this, mIntentReceiver, filter, ContextCompat.RECEIVER_EXPORTED);
or
registerReceiver(mIntentReceiver, filter, Context.RECEIVER_EXPORTED);

it hints "Must be one or more of: androidx.core.content.ContextCompat.RECEIVER_VISIBLE_TO_INSTANT_APPS, androidx.core.content.ContextCompat.RECEIVER_EXPORTED, androidx.core.content.ContextCompat.RECEIVER_NOT_EXPORTED"

enter image description here

it seems i did't satisfied this option interface. and it provide tips to change to RECEIVER_VISIBLE_TO_INSTANT_APPS, if i take that, the error disappear. but this's not perfect option.

答案1

得分: 1

In Sdk 34

ContextCompat.registerReceiver(
    requireContext(),
    smsReceiver,
    IntentFilter(SmsRetriever.SMS_RETRIEVED_ACTION),
    RECEIVER_NOT_EXPORTED
)
英文:

In Sdk 34

ContextCompat.registerReceiver(
    requireContext(),
    smsReceiver,
    IntentFilter(SmsRetriever.SMS_RETRIEVED_ACTION),
    RECEIVER_NOT_EXPORTED
)

答案2

得分: 0

在Sdk 34中使用权限

val intentFilter = IntentFilter(SmsRetriever.SMS_RETRIEVED_ACTION)
ContextCompat.registerReceiver(
    this,
    smsVerificationReceiver,
    intentFilter,
    SmsRetriever.SEND_PERMISSION,
    null,
    ContextCompat.RECEIVER_NOT_EXPORTED
)
英文:

In Sdk 34 with permission

val intentFilter = IntentFilter(SmsRetriever.SMS_RETRIEVED_ACTION)
ContextCompat.registerReceiver(
    this,
    smsVerificationReceiver,
    intentFilter,
    SmsRetriever.SEND_PERMISSION,
    null,
    ContextCompat.RECEIVER_NOT_EXPORTED
)

huangapple
  • 本文由 发表于 2023年6月29日 10:53:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76577792.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定