1

Is there any way to detect the pause state of the activity that has been started with startActivityForResult in Android.

I am launching the camera app in android to start recording a video however, after taking the video if the user doesn't click on either ok or cancel and simply clicks on the home button i would like to capture that event and delete the video taken and kill the camera. Is it possible in android?

Nav
  • 10,304
  • 20
  • 56
  • 83
  • You cannot get the "onPause event" of that activity, but you can check the current running apps and every interval check if it has changed, it is an overkill but would work... http://stackoverflow.com/questions/15567957/how-to-get-running-applications-icon-on-android-programmatically – TacB0sS Sep 08 '14 at 20:40
  • let me guess.. i will have to run it as a separate service as the main app will already be in paused state as the camera activity has not returned yet ??? – Nav Sep 08 '14 at 20:44
  • as you stated, the camera is another app, so killing it seems unlikely (which is a good thing). As for deleting the video taken, how the video is stored during the capture and until it is passed back to your application should not be the concern of your app, as it can change without requiring any notice, and may be different with different camera applications. – njzk2 Sep 08 '14 at 20:46
  • That, or you can let a thread sleep for an interval and check every now and again, or post an alert that would wake the app up and check every now and again, or use the first, and add a service to keep your application alive until you get a response... but again, these are all overkills, if possible please specify why do you need that info... – TacB0sS Sep 08 '14 at 20:47
  • All true... and that is why I was asking why you need to know!! – TacB0sS Sep 08 '14 at 20:48
  • because that is what I have been assigned to do as a requirement :( – Nav Sep 08 '14 at 20:54
  • **"I am launching the camera app in android"** - What camera app? If you mean whatever camera app is installed by default by whatever company who made the device you're dealing with (and remember there are a lot of them out there) then you're in trouble. It would be much easier to write your own "camera" code at which point you can control it any way you want. – Squonk Sep 08 '14 at 21:52
  • the default one...hmmm i was thinking about that.. can u please point to me some working custom camera implementation code – Nav Sep 09 '14 at 10:58
  • @Nav Did you ever come up with a solution for this? – cbalos Aug 18 '15 at 04:05
  • Yes and no...My requirement was that when a photo or video is taken and then the home button is tapped the camera and my app used to go into the background and the user can then kill the app but the photos and videos were still available via the android gallery app which can lead to all kinds of problems... – Nav Aug 18 '15 at 05:21
  • since i couldn't detect the pause state i changed the path to a custom path to which the image/video file is being written prior to call the camera intent... the default usually writes to DMIM folder etc. which is picked up by android gallery... – Nav Aug 18 '15 at 05:21
  • but if u write to another custom storage path then the images and videos are not picked up by the gallery app on android which can be an internal storage of your app itself which other apps can't read... and then if the user kills the app or it timeouts then afterwards u can delete the images/videos taken and other apps won't be able to access them in between. Hope that helps! Sorry had to write in three posts as SO wont allow to write long comments – Nav Aug 18 '15 at 05:21
  • @Nav thanks for the response. I thought this might be the only way to go. – cbalos Aug 19 '15 at 16:39

0 Answers0