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.
Related
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
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.
Greetings good people of Stack Overflow.
I am in need of the help of anyone who knows a bit about State Machines and/or Android Development.
So, I've pretty much got the whole design of my app's card game down, I've solved it with a State Machine Design Pattern, I have a CardGame class which in itself manages the different states that the GameState Class can go through and the transitions between them.
Now, my problem is that I do not know how to merge this Design Pattern into my Android App. The main issue is that I can't figure out how to only show a certain Player the actions he can carry out at the certain State the game is at. For example, once the game has just begun, the first Player should only be able to choose 3 of the 15 actions (methods) that the CardGame class allows.
If it where a simple command driven program, once a player would choose an action that he could not execute at a certain time, the program itself would simple printout a "You cannot carry out this action right now, choose another one." or something of that sort, but being it an Android App that manages Buttons and their OnClickListeners, I certainly have not found it to be very easy. I would be grateful if anyone could orient me as to what a viable solution would be, if there is, of course, a way to solve this inconvenient.
Is there a way to manage what Buttons should be printed according to the availability of a certain State's methods? Can one use some sort of flag to notify what the unavailable methods are in any way?
Thanks in advance, Agustin.
Just use a set to store currently valid actions, and update the set (and redraw buttons) when relevant state is changed.
I need help understanding how I would approach making an Android application that allows the user to scroll through 365 different bitmaps. I'm worried that I will go outside of the memory limits that android allows. I've tried googling, but haven't been able to understand how to approach the problem. Could someone write a very brief hint at where i can start researching this?
It depens on the source of those. I think you would like to use "lazy load ListView".
Checkout this
how about using any class that extends from AdapterView (like listView, gridView,...) ?
the idea is that since the user doesn't really see all of the views at the same time , you can re-use views that are being disappeared when scrolling , and show them as new ones .
watch the video of google called "the world of listView" .
anyway , if you don't wish to use this solution , consider being very "cheap" on the memory , as you are correct - android will kill your app if you use too much RAM .
you can read about handling bitmaps here .
I'm very new to Android development (think started yesterday) and in my application I'm trying to listen for when the camera is used to take a picture. Also, I need to listen for this action all the time such that my application can "close", but it'll still be listening in the background for when the camera takes an image (my application will execute almost entirely in the background once it's setup initially). Anyway, I've been doing a ton of reading and searching online and such and I've found that the best way, probably, to do this is to use a BroadcastReceiver, but what I've not seen is a good example of setting something like this up. I'm actually just very confused how to set up the BroadcastReceiver and how to start it working. Could someone provide me with a good example of how this should be done? Has anyone ever used something like this to listen for the camera taking a picture? Will this method work for me even if the application is "closed"?
Thanks in advance for any help you can provide!
Check this article out. It explains usage of the different available sensors their listeners and how to tap into them. It isn't explicitly giving you code for you camera but should be enough to jump start your progress provided you know the basics.