最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

broadcastreceiver - Solution of intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false) return false in Android API l

programmeradmin1浏览0评论

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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论