尝试获取电池电量时出现安全漏洞

时间:2013-05-26 10:57:45

标签: android battery receiver

尝试接收电池电量时,我收到一个securityException。

代码:

Intent batteryIntent = m_Context.getApplicationContext().registerReceiver(null, new             IntentFilter(Intent.ACTION_BATTERY_CHANGED));
        m_iRawLevel = batteryIntent.getIntExtra("level", -1);
        m_dScale = batteryIntent.getIntExtra("scale", -1);
        m_dLevel = -1;
        m_strLevel = "-1";

例外:

05-26 13:52:36.867: W/System.err(5960): java.lang.SecurityException: Unable to find app for caller android.app.ApplicationThreadProxy@421f7398 (pid=5960) when registering receiver null
05-26 13:52:36.867: W/System.err(5960):     at android.os.Parcel.readException(Parcel.java:1327)
05-26 13:52:36.872: W/System.err(5960):     at android.os.Parcel.readException(Parcel.java:1281)
05-26 13:52:36.872: W/System.err(5960):     at android.app.ActivityManagerProxy.registerReceiver(ActivityManagerNative.java:1880)
05-26 13:52:36.872: W/System.err(5960):     at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1130)
05-26 13:52:36.872: W/System.err(5960):     at android.app.ContextImpl.registerReceiver(ContextImpl.java:1105)
05-26 13:52:36.877: W/System.err(5960):     at android.app.ContextImpl.registerReceiver(ContextImpl.java:1099)
05-26 13:52:36.877: W/System.err(5960):     at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:348)
05-26 13:52:36.877: W/System.err(5960):     at com.uiu.bridgeservice.DeviceStatus.GetBatteryLevel(DeviceStatus.java:271)
05-26 13:52:36.877: W/System.err(5960):     at com.uiu.bridgeservice.BridgeManager.isBatteryStatusOK(BridgeManager.java:3412)
05-26 13:52:36.882: W/System.err(5960):     at com.uiu.bridgeservice.BridgeManager.isItPossibleToUpdate(BridgeManager.java:3806)
05-26 13:52:36.882: W/System.err(5960):     at com.uiu.bridgeservice.BridgeManager$4$1.handleMessage(BridgeManager.java:2136)
05-26 13:52:36.882: W/System.err(5960):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-26 13:52:36.882: W/System.err(5960):     at android.os.Looper.loop(Looper.java:137)
05-26 13:52:36.887: W/System.err(5960):     at android.app.ActivityThread.main(ActivityThread.java:4511)
05-26 13:52:36.887: W/System.err(5960):     at java.lang.reflect.Method.invokeNative(Native Method)
05-26 13:52:36.887: W/System.err(5960):     at java.lang.reflect.Method.invoke(Method.java:511)
05-26 13:52:36.887: W/System.err(5960):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
05-26 13:52:36.892: W/System.err(5960):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
05-26 13:52:36.892: W/System.err(5960):     at dalvik.system.NativeStart.main(Native Method)

编辑:

它可以与投票率有关吗?

因为不会一直抛出异常。

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

认为您只需要电池统计信息权限,请参阅http://developer.android.com/reference/android/Manifest.permission.html