辅助功能服务消耗大量电池

时间:2016-02-07 10:17:10

标签: android accessibility accessibilityservice android-accessibility

我正在使用这些权限并从大约10个不同的应用中检索内容。有没有更好的方法来降低电池消耗?

<accessibility-service
android:description="@string/accessibility_service_description"
android:accessibilityEventTypes="typeViewClicked|typeViewFocused|typeWindowStateChanged"
android:accessibilityFeedbackType="feedbackGeneric"
android:notificationTimeout="100"
android:canRetrieveWindowContent="true"
xmlns:android="http://schemas.android.com/apk/res/android" />

在辅助功能服务中读取事件:

@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    final int eventType = event.getEventType();
    String eventText = null;
    switch(eventType) {
        case AccessibilityEvent.TYPE_VIEW_CLICKED:
            eventText = "Focused: ";
            break;
        case AccessibilityEvent.TYPE_VIEW_FOCUSED:
            eventText = "Focused: ";
            break;
    }

    eventText = eventText + event.getContentDescription();

    // Do something nifty with this text, like speak the composed string
    // back to the user.
    speakToUser(eventText);
    ...
}

1 个答案:

答案 0 :(得分:0)

我建议重新考虑你对电池消耗的研究。不要说:

  

我的服务耗费了多少电池?

相反想想:

  

我的服务每分钟消耗多少电池?

请记住,您的服务在您的应用程序之上保持活跃。它一直在运行。因此,预计您的辅助功能服务将消耗比其他应用程序更多的电池。

话虽如此,您提供的信息无济于事。这些都不是罪魁祸首。基本配置对电池消耗的影响极小,只有在应用程序性质发生变化(您希望它做其他事情)时才能更改。不,没有金块配置机制来节省电池。这是一个错误的问题。您想问的问题类型是:

我的应用程序使用了多少数据,我可以等到它连接到Wi-Fi吗?我是否做了很多长时间的计算,可以一次性保存并完成所有操作?我的服务是否会导致屏幕上的时间超过必要的时间?

除此之外,与其他类型的应用程序相比,使用更多电池只是在可访问性服务的性质上,而且你无能为力。