I would like to know whether in Android the batt_attr_text file's location and content is the same regardless of the vendor or not? (Btw. same content means now that it has the same "attributes" listed in it...)
The reason I ask this is because of another post here. In the mentioned question, the questioner wants to know Voltage and Current. He/She gets an answer indicating, that the information can be found in a vendor-dependent file.
However what I'm looking for is the mAh capacity of the battery. I found that /sys/class/power_supply/battery/batt_attr_text contains what I need, but I'm not sure, that this file will be found on every Android device in the same form and in the same place.
Every constructive answer is appreciated. Thanks!
It's device specific, so it depends on the manufacturer. Have a look at this project: https://code.google.com/p/currentwidget/
Related
My app reads users' text files as input and do some stuff according to them. Currently it's done by setting MANAGE_EXTERNAL_STORAGE, but this permission is excessive as I don't access anything else.
I've been searching on https://developer.android.com/training/data-storage but have yet to come up with any good ideas. Is there any suggested manner to do so? Thanks :)
This shall help: https://developer.android.com/training/data-storage/shared/documents-files
(Though I'm not sure if your file type is supported.)
I'm just wondering how the following scenario can be solved:
I want to write a very simple app for my daughter. The app displays 4 colored fields on the activity and through speech output says something like "tap green". She should then tap the green field to get positive feedback. So far, so easy.
I then thought it might be nice if the app would also "grow" as she grows older. Maybe later I want to have a game mode where I display animals, numbers, vehicles, etc., so it would be nice if I could have something like "Shape sets" - basically a set of images along with a description of what the app should say for each image. Also easy enough - all you need is a set of images and an XML file describing the images.
BUT
I'd like to be able to install these "Shape sets" as additional APKs later on, so that I don't have to modify the app every time. I'd like to install the APKs, so that the contents are added to a specific sub folder on the SD card, into which my app looks to enumerate available "Shape sets".
If I ever published the app to the Play Store, other people should also be able to download the "Shape sets" I create (no need for user contributions, though).
Is that possible? If so, what would I have to do to have the Android OS "copy" the contents of an APK to a specific folder (lets say "/TapGame/Shape Sets/Animals") on the SD card? Or is there even another way of achieving what I want that I didn't think of?
The term "plugin architecture" just came to my mind as I wrote the question. Searching using that term I found this question: Extend my android app in different APK
It seems to provide a solution to my problem - I'll investigate this further, but please feel free to suggest other possible solutions!
Is that possible?
Um, sure.
If so, what would I have to do to have the Android OS "copy" the contents of an APK to a specific folder (lets say "/TapGame/Shape Sets/Animals") on the SD card?
Android won't do any of that. You have to do that. You would have to detect that a "shape set" APK was installed (either watching for package-installed broadcasts, scanning all installed apps for ones that seem to be a "shape set", etc.). Then you would have to arrange to copy whatever you wanted to wherever you wanted it, either by:
Asking the "shape set" app to do it (e.g., send a command to some IntentService), or
Using createPackageContext() and trying to do the copying from your main app
Or is there even another way of achieving what I want that I didn't think of?
Um, just use ZIP files that your app downloads itself from a well-known location. That corresponds to Dave Smith's final paragraph of his answer on the question you just linked to in your edit.
Or, just update the main app. I'm not quite certain what effort you think that you are saving otherwise.
Or, just keep the content online, using a Web service to indicate the available "shape sets" and downloading them as needed (with optional caching).
Fascinating question. If you really want to go for plug-ins then OSGi would probably be the way to go, but it's a lot of work to get to know and to use and seems like overkill in this case.
I don't know how your shapes are defined, but they are probably each defined in a separate file-set, providing the shape (maybe a png or jpg?) as well as the audio-file that will be used as a command for this shape. If the folder in which these file-sets are stored is fixed (TapGame/Shape Sets/...) the app could scan the folder each startup and the views could be generated accordingly (in this case, the activity cannot be build entirely in the XML-File, but must be partially done programmatically).
The Plugin-Aps would be rather easy. They are an apk which includes the file sets (jpg and mp3 or whatever). Started once they deposit all these files into the specified folder (they probably check before if these files exist) and then the apk can shut down again and be uninstalled.
on the next startup the Tap Game App would find the new symbols and include them into the game.
This seems rather straight forward to me. Another way would be to actually store the shapes and audio files on the internet and with each start of the App check if the number of shapes and audio-files has changed and create local copies of new ones. This would mean no downloads of apks... probably a more usual approach to the issue.
I am very interested to hear what you make of it, seems like a different approach then the norm, which is always cool to see.
I have a file on the Android SD card and would like to monitor any changes that happen to it through any external applications via code. Is there a way of doing that? Something like
http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx
http://developer.android.com/reference/android/os/FileObserver.html
has you tried FileObserver?
I don't think the system provides any sort of a callback type interface.
If you want that information I think you'd have to be check the contents of the file every so often and compare it to what you found last time. If it isn't equal then you know the file was touched by something else.
Surely this will end up being somewhat inefficient in terms of battery though I would imagine. If you must go this route I suggest as long of a duration in between checks as possible.
EDIT: I stand corrected. FileObserver looks like it'd be what you want. I've never run accross that one before. Props to #Grey.
I am still new to android programming, (wrote one small app so far) and I am also new to stack overflow. I am looking to write something that will listed for changes in a file, exactly like how file observer works. but the issue is the file im looking at receives changes from the kernel, and i realized that file observer does seem to pick up on changes unless it is done by the user. thanks.
I know this is old, but I figure I should Post the answer I found.
The solution is UEventObserver
doc: (http://www.androidjavadoc.com/1.1_r1_src/android/os/UEventObserver.html)
I found my answer in the "frameworks / base / services / java / com / android / server /" area of the android source code where they listen to changes reported form the kernel.
my implementation of the solution is here: https://github.com/gh123man/ICS_tablet_HW_rotationlock/blob/master/frameworks/base/services/java/com/android/server/RotationSwitchObserver.java
I believe there is no good solution. FileObserver will only report events that originate in user space - kernel originated events (i.e. to procfs file) are not reported. Further, the File operations won't work either, so you can can't check the hash, length, modified date, etc. of these files.
My observations are based on 2.3.6.
"the file im looking at receives changes from the kernel"
If you are referring to file from the procfs, or some other virtual-file, I fear inotify won't help you a lot...
search for "Q: Are there any limitations for use of inotify?"
Q: Are there any limitations for use of inotify?
Yes. Some filesystems (e.g. procfs or some network filesystems) don't emit
events in some cases.
I need to delete all the application data directories on the exit of an application:
/data/data/air.<appID>/cache/.AIR
/data/data/air.<appID>/cache/webviewCache
/data/data/air.<appID>/databases
But I get each time the "directory not found error"
Can anybody help me my a PRACTICAL code snippet? This is from my application descriptor:
<id>test01</id>
<filename>test01</filename>
<name>test01</name>
I know this is possible, but probably I'm typing in a wrong way the directories.
I know also this is not a best practice, but for security reasons I need to delete all the stagewebview cache and autofill form data.
File.applicationStorageDirectory is the thing you are looking for...
It points directly to the application's private storage directory.
Reference
the link is of not much help in this context. But I've found the solution. I was developing in debug mode so the correct application directory is /data/data/air.myappid.debug/ thanks anyway for the help! As of many of us know applicationdirectroy.nativepath gives an empty string on android.