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.

本文标签: