Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

How to cancel media.CapturePhoto() and media.selectPhoto()?
Started by JustAGuy1 Jul 03 2019 09:32 PM

- - - - -
7 replies to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

JustAGuy1

[GLOBAL: userInfoPane.html]
JustAGuy1
  • Observer

  • 22 posts
  • Corona SDK

Hi everyone,

The function native.showAlert( ) does return a handle and we can cancel the popup alert with native.cancelAlert(handle). Can we do the same with media.CapturePhoto() and media.selectPhoto() ? I got into a problem when my app resumes from background (system event.Type == "applicationOpen"), the screen to capture photo and select photo from album are still there. So my question is how do you programmatically dismiss /cancel media.CapturePhoto() and media.selectPhoto() ? Thank you.



[TOPIC: post.html]
#2

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,613 posts
  • Corona SDK

AFAIK, you can't cancel the media calls.

 

However, if anyone has a solution, I'd love to hear it too.



[TOPIC: post.html]
#3

JustAGuy1

[GLOBAL: userInfoPane.html]
JustAGuy1
  • Observer

  • 22 posts
  • Corona SDK

Still looking for a way to get around this but so far no way out

[TOPIC: post.html]
#4

JustAGuy1

[GLOBAL: userInfoPane.html]
JustAGuy1
  • Observer

  • 22 posts
  • Corona SDK

I need to solve this so bad, I am stuck. When media.capturePhoto() popup is left open, and when app resumes from background, it messed up my code, it throws errors. I need to close all popup panels programmatically. Anybody?



[TOPIC: post.html]
#5

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 502 posts
  • Corona SDK

Not something I've tried, but you could perhaps write a native plugin to kill any instance of the media app via the Android Intent mechanic, and then call this plugin when your app resumes. I don't know iOS but presumably there's a similar native workaround there too.

https://developer.android.com/reference/android/app/ActivityManager

I'm thinking killBackgroundProcesses might be what you need. Alternatively, calling moveTaskToFront for your own app might work too.

@roaminggamer I wonder if you could do something similar to kill the native media player in your own project if you don't manage to get the web popup approach to work?

[TOPIC: post.html]
#6

JustAGuy1

[GLOBAL: userInfoPane.html]
JustAGuy1
  • Observer

  • 22 posts
  • Corona SDK

Thank for the suggestions, but I don't think I am able to write a a native plugin. I am doing this on both iOS and Android. I think corona should support this. It is not reasonable to have an api bring up a camera and not have an api to close it. The thing is media.caprurePhoto() has a onComplete function, this function will be called after a photo is taken or user cancel the camera. Errors might happen when app resumes from background and in the system event listener I set up a lot of stuff, when user cancel the camera (which was left open from previous time), code in onComplete function will run and it causes errors because new info is setup in the system event listener ( event.type ==  "applicationOpen").  I think I cannot do anything about this.



[TOPIC: post.html]
#7

carloscosta

[GLOBAL: userInfoPane.html]
carloscosta
  • Contributor

  • 674 posts
  • Corona SDK

I think the proper behavior is just how it is.

I tried in a old app of mine that have media.CapturePhoto(). I opened the camera, pressed menu button on device to put app on background. Get app from background again, and it still is on media.CapturePhoto() like it should. Camera was open when I put it on pause, why should not be there if I resume it?

To cancel the camera you don't need to go to background and resume it, just need to press back button on your device, nothing more.

Maybe I missed something here and didn't understood why you wanted.

I can be wrong, but I think after camera is open corona can't do nothing because it not your app anymore that is working..its your camera app working. when you take the action...it will get back to your app.

If you want to integrate the camera on your app with buttons, etc you need to go native code, like QR Code plugin that have a back button. But this solution will lose lot's of options that your camera app have to take proper pictures.



[TOPIC: post.html]
#8

JustAGuy1

[GLOBAL: userInfoPane.html]
JustAGuy1
  • Observer

  • 22 posts
  • Corona SDK

carloscosta, Let me give you an example that the camera should be closed by itself. Say, your app generates a custom file ( say file1.xyz) and you send this file to your friend via email. Your friend tap on this file in their gmail app and it automatically launches your app and load the file1.xyz information, at this point the program needs to close the camera  (if the camera panel was left open) before loading the file1.




[topic_controls]
[/topic_controls]