Just want to register to video/photo taken events.
Hopefully, but not a must, the event will be triggered when the operation have finished, so I won't process half photos or half taken videos.
Already tried:
fileObserver = new FileObserver(dcimDir, FileObserver.ALL_EVENTS)
I see the events when traversing using a file manager app but not when a picture is taken nor when copying.
Ideas?
Found a way by registering to all sub directories of dcim (except the ones that start with a period):
new FileObserver(dcimDir.toString(), FileObserver.CLOSE_WRITE)
The reason I need to register to all of them is because different phones put picutes and videos in different folders - at least they are all under DCIM.
The reason the event is 'CLOSE_WRITE' is because I want to trigger after the photo/video is complete, so I won't process only half of the photo/video.
There is another way:
ContentProvider
See another SE thread for more info: Android -- How does Google+ instant upload work?
Related
I have checked other similar question and answers but not yet satisfied. I have a need where my app need to be notify whenever new photos arrive in the gallery so that it can process that new photo. I know apps like ES file explorer are using service for constantly monitoring the change in files and I am also doing the same.
What I am doing : Using intent service and AlarmManager to check every 30 minutes by querying MediaStore and send broadcast if any new photo is found since last scan.
What is required : Instead of firing intentService every 30 minutes I need to find a way where I can listen to new photos and send broadcast as soon as new photo is detected in device. I am not allowed to overburden device battery and give support all the way back from api level 11.
Can you suggest any way to achieve this ?
I'm looking to create a simple button in my android app that when clicked will take me to the app manager to a specific app where I can force close, uninstall, clear cache or data. Can someone help or point me to some examples to look at?
Use ACTION_APPLICATION_DETAILS_SETTINGS, with a package: Uri pointing to the app in question.
Note that this activity may not exist on all devices or may not be accessible by the current device user, so plan accordingly.
start following activity in your button click event.
startActivity( new Intent(android.provider.Settings.ACTION_APPLICATION_SETTINGS), 0);
I am interested in writing a screenshot app and want to learn the technique from this app.
After user takes a screenshot using power and volume buttons, the app opens up the screenshot without the user needing to pick an image from the gallery. I want to do something similar (save the user the step to navigate the gallery to get screenshots).
Does anyone how can an app read a screenshot as this app did ? (In the app's demo video this step is shown at time 0:30)
Edit
I've tried testing it on my nexus 5. I can see the screen shots are in folder /sdcard/Pictures/Screenshots. The directory permissions are:
drwxrwx--x root sdcard_rw 2015-08-30 01:42 Screenshots
I gave my app storage permissions. I used the following code in a service, but it didn't work:
FileObserver fileObserver = new FileObserver("/sdcard/Pictures/Screenshots") {
#Override
public void onEvent(int event, String path) {
Log.d("Test", "FileObserver event");
}
};
fileObserver.startWatching();
It should be running as a service in the background, which register a FileObserver, and perform action upon file added.
Or the service simply check the folder manually.
Edit:
Warning: If a FileObserver is garbage collected, it will stop sending events. To ensure you keep receiving events, you must keep a reference to the FileObserver instance from some other live object.
It means that local variable is definitely not working, put it into a field AND make sure your class will not be garbage collected, e.g. even Activity can be killed, and garbage collected afterwards.
At the moment my app has a service running which is fired every hour. This pulls any photos thats have been taken since last time it was open and uploads then to the server. This is done using the system content provider
Now what I want to do is send an intent to open the camera app, I am doing this like so...
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 0);
What I would like to happen is when the focus comes back to my app (after the user has taken a picture), I can open the service and that takes care of the photo.
However it seems like the photo is never added to the content provider. The service opens it and the cursos has a count of 0. Is there anything i can do so the system adds the photo to the content provider or do I need to handle this myself?
Edit
So I figure there no intents I can use to get it to save to the system. So it would seem my options are either
contentResolver.insert()
or
MediaStore.Images.Mediea.insertImage()
What is the difference between these 2 methods?
Edit
So I am starting to think google are clueless with there implementation of this feature. Take this link
http://developer.android.com/guide/topics/media/camera.html#intent-receive
You pass in the Uri and when it returns to your app it gives you the uri you gave it. If you did not specify a uri it doesn't return one. What is the point in that? Why would I want data I already have? Surely it would make sense the other way around. Or even just giving you basic data you need such as name, path, mimetype. Would that be too difficult?
Notify MediaScanner, when the scan is complete your photo will be added to the system database.
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.