Find Last time MediaScanner ran - android

I am trying to find out if droid stores the last time the MediaScanner had been run. Anyone know a way to check or if android stores that data?

According to the documentation there is no way to find the last time the MediaScanner ran. However, you can force a scan by using the scanFile() function:
http://developer.android.com/reference/android/media/MediaScannerConnection.html

I don't know if android saves the time log for the media scanner activity, however, you would know if the media scanner is already finished scanning by handling the ACTION_MEDIA_SCANNER_FINISHED intent.

Related

Android: how to tell when the camera is activated

I'm writing an Android app that the user can run in the background to detect when the camera is turned on(by the user, or by other apps). This should also detect even in the scenario where other apps (like facebook, instagram) do not use the default android camera app.
I've been searching but haven't seen any broadcasts that are sent whenever the camera is activated. So far, I've seen that there's Camera.open() that throws a RuntimeException if the camera is already in use by another app. So one way is to keep polling Camera.open(), but it's really expensive. Is there a better alternative?
Thanks
Edit: Sorry i didn't mention it clearly but what I want to do is to create some kind of camera usage log: what time it was turned on/off, how long was the duration, etc..
What happens internally is Camera API talks to CameraService and CameraService has mBusy variable which tracks whether camera is busy or not. And there is no API to get this mBusy flag out of service (without calling open())
I may be wrong, because I just glanced over it.
You can download Android source code (http://source.android.com/) and take a closer look yourself.
Files which could be interesting for you are:
\frameworks\base\services\camera\libcameraservice\CameraService.cpp
\frameworks\base\libs\camera\Camera.cpp
\frameworks\base\core\java\android\hardware\Camera.java
\frameworks\base\core\jni\android_hardware_Camera.cpp
One other idea. Try to look in the logs. In the case, if logs aren't turned off for Camera services/API, you can parse the logs to check when the camera was turned on or off. However, it may not work in OS 4.1, because Google limited reading of system logs.

Android let app know that media was mounted/unmounted while app was destroyed

Is there a way to let my app know that Media (SDCard) was mounted/unmounted while my app was turned off? I mean that my app and its services were Destroyed, not only stopped.
Probably, some ways to check MediaStore checksum are available?
Goal: decide if new music files were added or deleted in device memory to refresh general playlist.
Why not check if the SDCARD is mounted by using Environment.getExternalStorageState() upon restarting your app? The value you want it to be is Environment.MEDIA_MOUNTED. You could do it async and display a message somewhere stating that an update is in progress, however...
...if it's really the callback-ish thing you need, then you'll have to have a look at what John Willis wrote about registering a BroadcastReceiver.
You have register a broadcast receiver to receive an intent
android.intent.action.MEDIA_MOUNTED

Start Android application from NFC-tag with extra data

I can start my application by simply putting the phone on a NFC-tag. But I would like to take the idea one step further. Imagine a simple time-tracking application with two NFC-tags. The first will start (and download) the application and register a starttime. The other will also start (and download) the application, but register a stoptime.
My problem I'd like to solve is that I don't want my phone to know about these tags. The application should not need to have a list of tag-ids programmed and know what actions that is connected to each id. The tag should carry the information needed to start the action on the phone with the correct parameters.
Are there any information about how to accomplish this scenario? I have installed "nfc-eclipse-plugin" but doesn't understand how to use it to get my goal and even less how to get my application to read the extra data.
Thanks in advance
Roland
Your tags should be capable of storing NDEF messages. Such messages are automatically read out by Android and passed to your app in an Intent. Automatically installing and/or starting your app can be accomplished by putting an Android Application Record in your tag. Any additional information ("start" or "stop" indication) can be stored in a proprietary record.
You probably want to put the AAR as the last record of the NDEF message, as it is detected and acted upon by Android automatically, but is only supported since ICS. To make automatic installation work with Gingerbread, you can put an additional URI record or SmartPoster record with a Google Play Store link in it as the first record of the message. Your app should then filter (ACTION_NDEF_DISCOVERED) for this URI, so it will also start automatically on Gingerbread.

How to prevent Android to restart application after calling camera intent?

On low memory device I've got a problem after calling camera intent. When activity result should be received Android restart the whole app.
Have anybody faced same problem? Is there any solution?
I faced the same issue a while ago:
Android system stops application when launching Media Intent
Apparently there is no solution, so you have to make sure that you save and restore the application state.
Well i think, the problem could be: Image byte array is too big such that it touches the limit and android restarts the application so following is what will i do:
Calling the intent with some parameter telling to downsample the bytes it gonna send back.
OR
Implement your camera using surfaceview and then when user takes some picture, save it temporarily on sdcard and return only the path... then get the path in onActivityResult and use the picture.
Hope it helps.

Android: receiving MEDIA_BAD_REMOVAL notification

I have an application that scans the sd-card and make a list of video files stored in it. Then there is an option of playing the video files. All I want to know is
1- How can I register various actions or notifications like Action.Media.Unmount, Action.Media.Bad.Removal etc in my Manifest file
2- How can I use the braodcast receiver in my code.. I have tried couple of codes but they didn't work. If someone can give me of an example here, I shall be greatly thankful..
Thanks all
You really should read the documentation. It's a fairly simple method to register a BroadcastReceiver for those Intents.
Just read here and here.
If, after reading you still have some kind of problem, just say what error are you getting and the code/xml you're using.

Categories

Resources