英文:
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"
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
)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论