无障碍服务正在消耗大量电池。

3

我正在使用这些权限并从大约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);
    ...
}

你在谈论电池寿命之前是如何进行测试的? - GvSharma
1个回答

0
我建议重新考虑你对电池消耗的研究。不要问:
“我的服务总共消耗了多少电池?”
而是要想:
“我的服务每分钟消耗了多少电池?”
请记住,你的服务一直在应用程序之上运行,它会持续运行。因此,预计你的辅助功能服务将比其他应用程序消耗更多的电池。
话虽如此,你提供的信息并没有什么帮助。这些都不是罪魁祸首。基本配置对电池消耗的影响极小,只有当你的应用程序性质发生变化(你想让它做其他事情)时才能进行更改。没有什么黄金设置机制可以节省电池。这个问题是错误的。你想问的问题类型是:
“我的应用程序使用了多少数据,我能等到连接到 Wi-Fi 后再使用吗?我是否进行了很多长时间的计算,可以保存起来一次性完成?我的服务是否导致屏幕开启时间过长?”
除此之外,辅助功能服务消耗更多的电池是其固有特性,你无法改变这一点。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接