Configure battery usage of my application programmatically - android

I want to know how much my application using battery of user's mobile programmatically. I search for it but not able to find any specific solution for it.

If you are trying to configure usage for your battery from your app, you cannot. If
you are trying to know how much battery is left in your device you
can.
Suggestion: One thing you can do is start a session once your app opens and end it when you close. That way you can know how much battery was used. Again, other factors like background apps and multitasking comes into play hence you cannot identify it. Maybe these links can help you.
https://developer.android.com/topic/performance/power/battery-historian
https://developer.android.com/training/monitoring-device-state/battery-monitoring#java
Again I might be wrong here. Comments and edits are welcome.

Related

How to make apps stay in the background without being killed?

Hi so I got a new phone but the apps I need to stay in the background keep on being killed. I have turned off battery optimization and used the don'tkillmyapp said it was 100% not much help. I looked around and someone mentioned that you can make apps stay in the background using adb. Can you please link a website on how to do that since I'm a beginner or you can just tell me how. Please and thank you.
Use Worker. You can use workers for a specific task or to run others periodically. Here I leave the link for more information.
https://www.google.com/url?sa=t&source=web&rct=j&url=https://developer.android.com/reference/androidx/work/Worker&ved=2ahUKEwiQjZyz6JbuAhUm2FkKHQheAnIQFjABegQIARAB&usg=AOvVaw3RUYn3s9t_S_Mks1x4p8H0

Android location tracking

I'm a beginner in android development. I need some idea about how can I make an app which can track a phone's live location. I want to use the same app on 2 devices and both of them should be able to track each other. Can someone please help?
the good starting point is https://developer.android.com/training/location where you can find examples and best practices. Depending on your application please consider a suitable strategy (background tracking, geofencing, and impact on the battery). The second thing you have to solve is how to exchange/share information between devices. There are ways how to deal with it. For example, google API, web socket or something else. Sorry for the general answer.

Tracking screen time in android

for a university project I have to track the screen time of an android smartphone. It's hard to find proper search results, because my search engines do only suggest apps, that already do this for you. I am interested in how these apps do this. I assume, there is a native API on android which supports you with this. Unfortunately, I can't find anything that already does this.
The app is supposed to run a little service which tracks the time of the screen activity and other stuff (like location). It would be great, if someone of you can help me out on where to look for examples and where to find information about the android API.
Edit:
To be a bit more precise: It's about the overall screen time, not about the screen time a specific app has.
Broadcast Actions might be a solution for this,
ACTION_SCREEN_ON
ACTION_SCREEN_OFF
https://developer.android.com/reference/android/content/Intent.html#ACTION_SCREEN_ON
https://developer.android.com/reference/android/content/Intent.html#ACTION_SCREEN_OFF

How to retrieve app usage statistics of an android device?

I'm constantly trying new apps and my phone is getting cluttered with old apps, I no longer use. So, I thought I'd develop a simple app to help me out. There are similar apps, but none does exactly what I want:
I would like to have a list of apps which I've installed in the last month, which I've used X number of times (for easy access: They may be keepers!) as well as those I've not used in Y weeks.
Is there any way to get app usage statistics with Android? I guess ActivityManager might help me to gather that statistics, but is there a way to read just when an app has been used last? Or how many times in a given period?
Any tips will be most welcome :)
You can try out my app for uninstallation of the apps you don't need : https://play.google.com/store/apps/details?id=com.lb.app_manager .
Also, if you wish to find exact usage statistics of your apps, you can use my app this way: find "settings" (the app itself) inside the list (you can perform a search query), choose to make a shortcut of it, and then choose on the dialog "Usage Statistics". This way you can perform both the operations you wanted.
I also plan on adding this feature somehow in the future, but that's what you can do for now.
Here's a screenshot (it's the first on what I show here) :

Android BatteryManager Class Advice

I am trying to build an app which I've never tried before and seeking your help in deciding how to go about it.
I intend to make an app in which I'm showing a custom battery level to the user. I've seen numerous apps in the market that do the same but I don't know how exactly to achieve it.
For Example I intend to create something like below but with my own custom images:
https://play.google.com/store/apps/details?id=com.macropinch.pearl
https://play.google.com/store/apps/details?id=com.geekyouup.android.widgets.battery
I've researched and came to know that BatteryManager class in android.os will be the one to use it.
But my main 2 troubles are:
I want to show an image which will keep on changing based on the current level of the battery.
How to PIN the app on the phone home screen as a widget so that it sticks on the home screen indicating the current battery level.
The approach that I've in my mind:
For first I think I can call the battery current level method at regular intervals say every 5 seconds and then based on the level of the battery I change the image accordingly. Although I think this can't be the best way to do it. Please guide if this approach is right. If not then please suggest what could be a more effective and efficient approach.
Also how should I change the image. Is sprite images the best way or is there any other way to do it easily and effectively?
For second, I've never tried it so you have to guide me how to do this exactly.
If you can share some code that can help me achieve my goal that would be a great help.
Try reading through tutorials on android developer site.

Categories

Resources