我有一个小部件可以在它想要的时候工作而不是......好吧它没有!具体来说,如果我重新启动手机并点击小部件,事情就会发生。也许有一段时间我可以继续点击小部件,一切正常。但最终(可能是一个小时??)它只是停止工作。从 logcat 来看,我的任何代码都没有被执行,所以就好像 tap 从来没有发送到我的应用程序。我的思考过程是,由于发生这种情况时我的任何代码都不会执行,所以问题一定是在清单中,或者是我不知道的其他问题。
这是它工作时的logcat。这里的最后一行来自我的代码:
07-20 13:00:54.638: E/MP-Decision(1265): UP Ld:85 Nw:1.990000 Tw:140 rq:1.000000 seq:141.000000
07-20 13:00:54.818: I/InputReader(533): Touch event's action is 0x0 (deviceType=0) [pCnt=1, pending(waiting finished signal)=0, s=0.4 ]
07-20 13:00:54.818: I/InputDispatcher(533): Delivering touch to current input target: action: 0x0
07-20 13:00:54.818: D/lights(533): write_int /sys/class/leds/button-backlight/brightness = 255
07-20 13:00:54.818: I/PowerManagerService(533): Ulight 0x3->0x7|0x0
07-20 13:00:54.818: D/PowerManagerService(533): setLightBrightness : mButtonLight : 51
07-20 13:00:54.908: I/InputReader(533): Touch event's action is 0x1 (deviceType=0) [pCnt=1, pending(waiting finished signal)=0, s=]
07-20 13:00:54.908: I/InputDispatcher(533): Delivering touch to current input target: action: 0x1
07-20 13:00:54.918: I/AudioPolicyManagerBase(229): getSituationVolume: isBTConnected:0 isHeadConnected:0
07-20 13:00:54.918: V/AudioPolicyManagerBase(229): getParamFromPolicy deviceInt = 0, situationInt = 1, situationVolume = 0.500000
07-20 13:00:54.918: D/AudioService(533): playSoundEffect()
07-20 13:00:54.918: W/AudioTrack(533): Minimum buffer size corrected from 2048 to 4096
07-20 13:00:54.918: V/AudioPolicyManagerBase(229): startOutput() output 1, stream 1, session 18
07-20 13:00:54.918: V/AudioPolicyManagerBase(229): getDeviceForStrategy() from cache strategy 0, device 2
07-20 13:00:54.918: V/AudioPolicyManagerBase(229): changeRefCount() stream 1, count 1
07-20 13:00:54.918: V/AudioPolicyManagerBase(229): getDeviceForStrategy() from cache strategy 0, device 2
07-20 13:00:54.918: V/AudioPolicyManagerBase(229): getNewDevice() selected device 2
07-20 13:00:54.918: V/AudioPolicyManagerALSA(229): setOutputDevice() output 1 device 2 delayMs 0 force 0
07-20 13:00:54.918: V/AudioPolicyManagerALSA(229): setOutputDevice output :0x1 mCurDevice:0x2
07-20 13:00:54.918: V/AudioPolicyManagerALSA(229): setOutputDevice() setting same device 2 or null device for output 1
07-20 13:00:54.918: D/PHCA_PhcaAppWidgetProvider(2316): onReceive(); action = com.skipmorrow.phca.PhcaAppWidgetProvider.WIDGET_CLICKED
这是它不起作用时的logcat。
07-20 12:53:41.012: I/InputReader(534): Touch event's action is 0x0 (deviceType=0) [pCnt=1, pending(waiting finished signal)=0, s=0.160 ]
07-20 12:53:41.012: I/InputDispatcher(534): Delivering touch to current input target: action: 0x0
07-20 12:53:41.012: D/lights(534): write_int /sys/class/leds/button-backlight/brightness = 255
07-20 12:53:41.012: I/PowerManagerService(534): Ulight 0x3->0x7|0x0
07-20 12:53:41.012: D/PowerManagerService(534): setLightBrightness : mButtonLight : 51
07-20 12:53:41.112: I/InputReader(534): Touch event's action is 0x1 (deviceType=0) [pCnt=1, pending(waiting finished signal)=0, s=]
07-20 12:53:41.112: I/InputDispatcher(534): Delivering touch to current input target: action: 0x1
07-20 12:53:41.112: I/AudioPolicyManagerBase(230): getSituationVolume: isBTConnected:0 isHeadConnected:0
07-20 12:53:41.112: V/AudioPolicyManagerBase(230): getParamFromPolicy deviceInt = 0, situationInt = 1, situationVolume = 0.500000
07-20 12:53:41.112: D/AudioService(534): playSoundEffect()
07-20 12:53:41.112: W/AudioTrack(534): Minimum buffer size corrected from 2048 to 4096
07-20 12:53:41.112: V/AudioPolicyManagerBase(230): startOutput() output 1, stream 1, session 153
07-20 12:53:41.112: V/AudioPolicyManagerBase(230): getDeviceForStrategy() from cache strategy 0, device 2
07-20 12:53:41.112: V/AudioPolicyManagerBase(230): changeRefCount() stream 1, count 1
07-20 12:53:41.112: V/AudioPolicyManagerBase(230): getDeviceForStrategy() from cache strategy 0, device 2
07-20 12:53:41.112: V/AudioPolicyManagerBase(230): getNewDevice() selected device 2
07-20 12:53:41.112: V/AudioPolicyManagerALSA(230): setOutputDevice() output 1 device 2 delayMs 0 force 0
07-20 12:53:41.112: V/AudioPolicyManagerALSA(230): setOutputDevice output :0x1 mCurDevice:0x2
07-20 12:53:41.112: V/AudioPolicyManagerALSA(230): setOutputDevice() setting same device 2 or null device for output 1
07-20 12:53:41.112: V/AudioPolicyManagerBase(230): releaseOutput() 1
我看不出有什么突出的问题。
这是 widgetProvider 的清单部分:
<receiver android:name="com.skipmorrow.phca.PhcaAppWidgetProvider" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
<action android:name="com.skipmorrow.phca.PhcaAppWidgetProvider.WIDGET_CLICKED" />
<action android:name="com.skipmorrow.phca.PhcaAppWidgetProvider.VARIABLE_UPDATED" />
<action android:name="android.appwidget.action.APPWIDGET_DELETED"/>
<action android:name="CORRECT_PIN_ENTERED_FOR_WIDGET"/>
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/phca_widget_info" />
</receiver>
顺便说一句,我使用的是运行 ICS 的三星 Galaxy S3。我的应用有 minSdkVersion="8" 和 targetSdkVersion="8"
周末没有答案,但我做了一些故障排除。我仍然有问题,但我确实有其他信息。
小部件确实从为小部件提供文本的后台服务中得到更新。但是当它们被点击时,这些小部件并不总是做它们应该做的事情。换句话说,即使没有正确处理点击,我仍然可以更新小部件中的文本,因此小部件不会完全损坏,如果有帮助的话。似乎点击响应来来去去。也就是说,重新启动后,点击似乎可以工作一段时间,然后可能会停止工作一段时间,然后再次开始工作。我的 AppWidgetProvider 覆盖了 onUpdate、onEnabled、onDeleted、onDisabled 和 onReceive 方法,但我只使用 onReceive 方法并手动跟踪每个意图。onReceive 方法的第一行写入日志,所以我可以看到当点击不起作用时,
会不会是权限问题?还是我没有正确注册接收器?