cordova-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From riknoll <>
Subject [GitHub] cordova-plugin-media-capture pull request: CB-10554: Implementing ...
Date Wed, 27 Apr 2016 19:51:29 GMT
GitHub user riknoll opened a pull request:

    CB-10554: Implementing plugin save/restore API for Android

    The purpose of this PR is to handle the case where the Webview gets destroyed in the background
while a capture activity is in the foreground. #51 was invalidated by some updates that were
recently made to the plugin to handle overlapping permission and activity requests.
    Also worth noting is that I did something different than the usual resume event API for
getting pending plugin callback results. Instead of returning the native result to the javascript
directly, this plugin needs to first wrap the results returned by the native code in a `MediaFile`
object for those results to be useful. For that reason, I altered the plugin to expose two
document events on Android that the user can subscribe to rather than the cordova-android
generated resume event. These events directly return the wrapped result rather than the raw
native one. It ends up looking like this:
    function onDeviceReady() {
        // pendingcaptureresult is fired if the capture call is successful
        document.addEventListener('pendingcaptureresult', function(mediaFiles) {
            // Do something with result
        // pendingcaptureerror is fired if the capture call is unsuccessful
        document.addEventListener('pendingcaptureerror', function(error) {
            // Handle error case
    document.addEventListener('deviceready', onDeviceReady);
    Whereas using the resume event directly would require us to expose a helper API on Android:
    function onDeviceReady() {
        document.addEventListener(resume, function(event) {
            if(event.pendingResult && event.pendingResult.pluginServiceName === "Capture")
                if(event.pendingResult.pluginStatus === "OK") {
                    var rawMediaFiles = event.pendingResult.result;
                    // Here, we would need to expose some weird helper function to deal with
the native result
                    var mediaFiles = capture.wrapMediaFiles(mediaFiles);
                    // Do something with result
                } else {
                    var error = event.pendingResult.result;
                    // Handle the error case
    document.addEventListener('deviceready', onDeviceReady);
    I think this makes the API a bit cleaner and also opens the way for plugins that do much
more heavy javascript work before returning callback results. This hasn't really come up before
because the other two core plugins that had this issue (camera and contacts) could just pass
the native result directly to the javascript.
    I'd appreciate some feedback on this API and if it seems okay I might update the Android
plugin guide with an example so that other plugins can use this pattern.

You can merge this pull request into a Git repository by running:

    $ git pull CB-10554

Alternatively you can review and apply these changes as the patch at:

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #60


If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at or file a JIRA ticket
with INFRA.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message