admin管理员组文章数量:1415467
You need to use explicit intent.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
Intent intent = new Intent(ACTION_USB_PERMISSION);
intent.setPackage(mContext.getPackageName());
mPermissionIntent = PendingIntent.getBroadcast(mContext, 0, intent, PendingIntent.FLAG_MUTABLE);
} else {
mPermissionIntent = PendingIntent.getBroadcast(mContext, 0, new Intent(ACTION_USB_PERMISSION), PendingIntent.FLAG_UPDATE_CURRENT);
}
The setPackage(mContext.getPackageName())
restricts the intent to your own app.
This makes it an explicit intent, as it targets a specific receiver in the same app.
If setPackage()
were removed and no specific component was set, the system would look for any app that could handle ACTION_USB_PERMISSION
, making it implicit.
本文标签:
版权声明:本文标题:broadcastreceiver - Solution of intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false) return false in Android API l 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745165653a2645659.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论