我在将应用程序推送到 Google Play 控制台时遇到问题。
广播接收器注册不正确
面向 Android 13 或更高版本的应用必须在调用 registerReceiver() 时指定导出行为。未指定的导出行为可能会导致您的应用程序崩溃。
您的应用面向 Android 13 或更高版本,并注册非系统广播接收器,但未在以下位置指定其导出行为:
更新您的应用程序,以便它指定注册广播接收器的导出行为。
我有regiserReceiver,就像下面的代码。
ContextCompat.registerReceiver(this, mMessageReceiver, filter, ContextCompat.RECEIVER_NOT_EXPORTED);
你必须在Manifest文件中将导出设置为true或false
<receiver android:name=".MyBroadcastReceiver" android:exported="false">
<intent-filter>
<action android:name="APP_SPECIFIC_BROADCAST" />
</intent-filter>
</receiver>
此外,当您尝试发送这样的广播时:
val intent = Intent().apply {
action = "YOUR_ACTION_HERE"
`package` = "YOUR_ACTIVITY_PACKAGE_NAME"
}
sendBroadcast(intent)
这是注册广播的最后一步:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
getActivity().registerReceiver(receiver, intentFilter, Context.RECEIVER_NOT_EXPORTED);
} else {
getActivity().registerReceiver(receiver, intentFilter);
}