我遇到了一个问题,它只发生在 MIUI 设备上。我正在尝试使用以下代码共享一些文本
private fun shareTextWithCallback(text: String) {
val title = getString(resId)
val intent = Intent(Intent.ACTION_SEND)
.putExtra(Intent.EXTRA_TEXT, text)
.setType("text/plain")
val receiver = Intent(requireContext(), ShareCompletedReceiver::class.java)
val pendingIntent = PendingIntent.getBroadcast(requireContext(), 0, receiver, PendingIntent.FLAG_UPDATE_CURRENT)
val chooser = Intent.createChooser(intent, title, pendingIntent.intentSender)
startActivity(chooser)
}
在从意图选择器中选择项目后的 MIUI 设备上,没有任何反应。这就是我在日志中发现的:
2020-11-30 12:33:15.526 782-1085/? D/com.android.server.am.ExtraActivityManagerService:
MIUILOG- Permission Denied Activity :
Intent { act=android.intent.action.SEND typ=text/plain flg=0xb080001
cmp=org.telegram.messenger/org.telegram.ui.LaunchActivity clip=MY_TEXT_HERE .... }
当我只是尝试发送 ACTION_VIEW 意图时也会发生同样的情况:
fun Fragment.showBrowser(link: String) {
val intent = Intent(Intent.ACTION_VIEW).apply { data = Uri.parse(link) }
startActivity(intent)
}
D/com.android.server.am.ExtraActivityManagerService:
MIUILOG- Permission Denied Activity :
Intent { act=android.intent.action.VIEW dat=LINK... flg=0x3000000
cmp=com.android.chrome/com.google.android.apps.chrome.IntentDispatcher }
我搜索了类似的问题,但它们都是关于从后台启动活动(例如广播接收器),而我的情况并非如此。提前感谢您的帮助