这种方法相当粗糙,但它可能会有所帮助。您可以使用现有的 BatteryManager 广播来跟踪应用程序处于活动状态时整体电池电量的变化。
Knowing when your app is active is a separate issue. If your app consists entirely of Activities, then you can get good results by starting to track whenever any of your Activities' onResume()
methods is called, and stopping tracking in onPause()
. If you can have all your Activities derive from a single base Activity class, then this is quite easy. See How to detect when an Android app goes to the background and come back to the foreground for suggestions on how to track this.
If your app is more complex, and the smart stuff happens in a longer-running component like a Service, then it's much harder.
This is crude, but at least it would help you distinguish "playing 3D games" from "using my app".