Android 的安全异常
我有这样的代码:
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELPHONY_SERVICE);
Class clase = Class.forName(tm.getClass().getName());
Method m = clase.getDeclaredMethod("getITelephony");
m.setAccesible(true);
ITelephony it = (ITelephony) m.invoke(tm);
it.supplyPIN("1111");
当我尝试调用方法 *supplyPIN("1111")*
时,出现 SecurityException。 错误消息是:
java.lang.SecurityException: Neither user 10066 nor current process has android.permission.MODIFY_PHONE_STATE.
在我的 Manifest.xml
中,我拥有 MODIFY_PHONE_STATE
权限。
有什么想法吗?
谢谢
I have this code:
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELPHONY_SERVICE);
Class clase = Class.forName(tm.getClass().getName());
Method m = clase.getDeclaredMethod("getITelephony");
m.setAccesible(true);
ITelephony it = (ITelephony) m.invoke(tm);
it.supplyPIN("1111");
I have a SecurityException when I try to invoke the method *supplyPIN("1111")*
.
The error message is:
java.lang.SecurityException: Neither user 10066 nor current process has android.permission.MODIFY_PHONE_STATE.
In my Manifest.xml
I have the MODIFY_PHONE_STATE
permission.
Any idea?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
确保它与此 URL 处的此字符串匹配:
MODIFY_PHONE_STATE
Insure that it matches this string at this URL:
MODIFY_PHONE_STATE
ITelephony 是 android 的内部类,你不应该使用它
ITelephony is an internal class of android, you should not be using it
请参考这个答案:如何授予系统权限
您需要遵循类似的方法android.permission.MODIFY_PHONE_STATE
如果您已经完成此操作,请参阅上面页面上的更多链接,其中提供了有关如何使用权限的更多详细信息。
希望这有帮助。
Refer this answer: How to grant system permission
You need to follow a similar approach for the android.permission.MODIFY_PHONE_STATE
If you have done this already, refer to more link on the above page that gives more details on how permission are used.
Hope this helps.