问题描述
我编写了一个尝试修改电话呼叫状态的应用程序.它在 Android 2.2 或更低版本上运行良好,但在 Android 2.3 上抛出异常,因为缺少 android.permission.MODIFY_PHONE_STATE 权限(我在 AndroidManifest.xml 上声明了此权限).任何的想法?以下是异常日志:
I write an application that attempts to modify phone call state. It works well on Android 2.2 or less, but throw an exception on Android 2.3 because of the lack of permission on android.permission.MODIFY_PHONE_STATE permission (I declared this permission on AndroidManifest.xml). Any idea? Below is the exception log:
01-15 09:14:23.210: ERROR/AndroidRuntime(404): FATAL EXCEPTION: main
01-15 09:14:23.210: ERROR/AndroidRuntime(404): java.lang.RuntimeException: Unable to start receiver test.PhoneReceiver: java.lang.SecurityException: Neither user 10031 nor current process has android.permission.MODIFY_PHONE_STATE.
01-15 09:14:23.210: ERROR/AndroidRuntime(404): at android.app.ActivityThread.handleReceiver(ActivityThread.java:1780)
01-15 09:14:23.210: ERROR/AndroidRuntime(404): at android.app.ActivityThread.access$2400(ActivityThread.java:117)
01-15 09:14:23.210: ERROR/AndroidRuntime(404): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:978)
01-15 09:14:23.210: ERROR/AndroidRuntime(404): at android.os.Handler.dispatchMessage(Handler.java:99)
01-15 09:14:23.210: ERROR/AndroidRuntime(404): at android.os.Looper.loop(Looper.java:123)
01-15 09:14:23.210: ERROR/AndroidRuntime(404): at android.app.ActivityThread.main(ActivityThread.java:3647)
01-15 09:14:23.210: ERROR/AndroidRuntime(404): at java.lang.reflect.Method.invokeNative(Native Method)
01-15 09:14:23.210: ERROR/AndroidRuntime(404): at java.lang.reflect.Method.invoke(Method.java:507)
01-15 09:14:23.210: ERROR/AndroidRuntime(404): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-15 09:14:23.210: ERROR/AndroidRuntime(404): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-15 09:14:23.210: ERROR/AndroidRuntime(404): at dalvik.system.NativeStart.main(Native Method)
推荐答案
MODIFY_PHONE_STATE 是系统专用权限,因此不允许应用获取.
MODIFY_PHONE_STATE is a system-only permission, so apps are not allowed to get it.
这可能与之前版本的平台有所不同,但这没关系,因为它只保护私有 API,所以如果您正在做一些需要它的事情,那么您正在使用不受支持的私有 API,并且会导致一些事情就像您的应用在不同版本的平台上崩溃一样.
This may have changed from previous versions of the platform, but that is okay because it is only protecting private APIs, so if you are doing something that requires it, you are using private APIs that are not supported and will result in things like your app breaking on different builds of the platform.
您包含的堆栈爬取不完整,因此无法判断您实际在做什么.
The stack crawl you include is not complete, so there is no way to tell what you are actually doing.
这篇关于如何为在 Gingerbread 上运行的应用程序授予 MODIFY_PHONE_STATE 权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!