【原创】android 7.0 通知报错 java.lang.SecurityException: You need MANAGE_USERS permission to: check if specified user a managed profile outside your profile group
2017-03-01 18:23
363 查看
项目中在后台发送通知,突然某一天测出在Android 7.0上通知发送失败,那么根据提示,我们尝试加了MANAGE_USERS权限,看起来是个系统级别权限,验证后果然无效。接着在搜索后都无果,似乎大家都没遇到过,很是诡异。
从报错看可能跟系统用户有关,也许关联了什么权限没有获得。开始只能通过try/catch, 这样在前台可以收到消息。那在后台还是有问题。
开始我有几个怀疑点:
1、7.0 修改了Notification的构建方式。 但查看api更新说明,没有提及。
2、当时测出问题是在Nexus6, 从这个权限名来看 MANAGE_USERS,怀疑与系统的用户管理权限有关。
后来经过很长时间终于找到这个问题的根本原因。
首先重建一个Demo在7.0上测试一切正常,说明很有可能是我们自己工程的问题,后来发现在自定义的MyApplication有一个方法叫getUserId(), 而在Notification构建时发现竟然有一个相同的方法:
sdk 24(7.0代码):
由于这个Context 在Builder构造的时候传的是Application context, 所以很大可能就是和系统方法冲突了。
但是我又看了下,7.0以前的代码也有同样的方法,只是位置略有不同,至此还是不能解释为什么只有7.0有问题。
sdk 23:
然后我又找出手机对应的代码版本,7.0.0_r1, 有一段提交记录:
正是由于加了 callingUserId != userId 这个权限判断,才会抛出这个异常,虽然系统通知的流程我不太熟,但至此已经可以确认此问题的根本原因。
所以这个bug很巧,只有在7.0上,你的代码里有这个方法的时候才会出现。那么改法就比较简单了,修改自己的方法即可。
从报错看可能跟系统用户有关,也许关联了什么权限没有获得。开始只能通过try/catch, 这样在前台可以收到消息。那在后台还是有问题。
开始我有几个怀疑点:
1、7.0 修改了Notification的构建方式。 但查看api更新说明,没有提及。
2、当时测出问题是在Nexus6, 从这个权限名来看 MANAGE_USERS,怀疑与系统的用户管理权限有关。
后来经过很长时间终于找到这个问题的根本原因。
首先重建一个Demo在7.0上测试一切正常,说明很有可能是我们自己工程的问题,后来发现在自定义的MyApplication有一个方法叫getUserId(), 而在Notification构建时发现竟然有一个相同的方法:
sdk 24(7.0代码):
由于这个Context 在Builder构造的时候传的是Application context, 所以很大可能就是和系统方法冲突了。
但是我又看了下,7.0以前的代码也有同样的方法,只是位置略有不同,至此还是不能解释为什么只有7.0有问题。
sdk 23:
然后我又找出手机对应的代码版本,7.0.0_r1, 有一段提交记录:
正是由于加了 callingUserId != userId 这个权限判断,才会抛出这个异常,虽然系统通知的流程我不太熟,但至此已经可以确认此问题的根本原因。
所以这个bug很巧,只有在7.0上,你的代码里有这个方法的时候才会出现。那么改法就比较简单了,修改自己的方法即可。
相关文章推荐
- 推送报 java.lang.SecurityException You need MANAGE_USERS permission to check
- 异常java.lang.SecurityException: You need MANAGE_USERS permission to……
- Call requires permission which may be rejected by user: code should explicitly check to see if permi
- startInstrumentation asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL
- facebook permissions : How to check if the user has already allowed publish_stream for your app
- Failed to export using the options you specified. Please check your options and try again
- Call requires permission which may be rejected by user: code should explicitly check to see if permi
- Everything You Need to Know About Rooting Your Android Phone
- Error: Could not find gradle wrapper within Android SDK. Might need to update your Android SDK. Looked here: C:\Users\Administrator\AppData\Local\Android\sdk\tools\templates\gradle\wrapper
- All you need to know about tethering with your Android device
- You need perl module Net::SNMP to run check_openmanage in SNMP mode
- Call requires permission which may be rejected by user: code should explicitly check to see if permi
- iOS通知 you still need to add "remote-notification" to the list of your supported UIBackgroundModes
- Your Apple ID account is also attached to other iTunes providers. You will need to create a new user
- call requires permission which may be rejected by user;code should explicitly check to see if permis
- Check if user has access to CI
- ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
- How to: Check if User Has Certian Permission – Facebook API (通过facebook提供的php版本的SDK发送feed)
- Android上下TabHost设置及Did you forget to call 'public void setup(LocalActivityManager activityGroup)解决方法
- [Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL s