cordova-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Darryl Champagne (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CB-2533) App crashes after taking a picture with the camera
Date Tue, 26 Feb 2013 23:56:12 GMT

    [ https://issues.apache.org/jira/browse/CB-2533?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13587749#comment-13587749
] 

Darryl Champagne commented on CB-2533:
--------------------------------------

I can reproduce this in my application on a Samsung S3, model GT-I9305, running 4.1.1, with
Cordova 2.3.0.  I attempted to cherry-pick the checkin: "5ca233779d11177ec2bef97afa2910d383d6d4a2
This is as far as we can get fixing the Camera plugin by recovering state	Joe Bowser	11/8/2012
6:42:28 PM", however the call to appView.pluginManager.getPlugin that were added to DroidGap::onActivityResult
always fails, because the service name is not the class name.  Adding a simple function PluginManager::getPluginByClassName
addresses the NPE in DroidGap, however CameraLauncher still requires additional state saved,
such as ImageUri, but Plugins do not currently have an equivalent to onSaveInstanceState,
so this has to be hacked in.

This was my (trivial) getPluginByClassName:
{code}
    public CordovaPlugin getPluginByClassName(String cName) {
        for (PluginEntry entry : this.entries.values()) {
            if ((cName != null) && (entry.pluginClass != null) && entry.pluginClass.equals(cName))
{
                Log.d(TAG, "getPluginByClassName found class name " + cName);
                CordovaPlugin plugin = entry.plugin;
                if (plugin == null) {
                    plugin = entry.createPlugin(this.app, this.ctx);
                }
                return plugin;
            }
        }
        Log.d(TAG, "getPluginByClassName did not find class name " + cName);
        return null;
    }
{code}
                
> App crashes after taking a picture with the camera
> --------------------------------------------------
>
>                 Key: CB-2533
>                 URL: https://issues.apache.org/jira/browse/CB-2533
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Android
>    Affects Versions: 2.4.0
>         Environment: Samsung Galaxy S3, Android 4.1.1
>            Reporter: Dean Kooiman
>            Assignee: Joe Bowser
>
> Hi,
> I found a bug in cordova during tests on my Samsung Galaxy S3 with android 4.1.1 
> I have tried using both camera.getPicture as well as capture.captureImage
> In both cases the CameraLauncher successfully starts.  
> Both functions only succeed when the user takes a picture in landscape mode (phone is
horizontal). When the picture is taken in portrait mode (phone vertical) the application will
fail with a NPE in DroidGap, this is due to DroidGap loosing its reference to the activityResultCallback
when its orientation changes.
> I am able to reproduce this using the default creation and camera examples:
> 1. Create the project: C:\Programming\cordova\cordova-android\framework>bin\create
C:\Users\dean\workspace-android\DeanTest2 com.kooiman DeanTest2
> 2. Overwrite assets/www/index.html with the complete example from: http://docs.phonegap.com/en/2.4.0/cordova_camera_camera.md.html#Camera
> 3. Deploy the application to a Samsung Galaxy S3
> 4. Take a picture in portrait mode and see the failure.
> I can successfully get the callback by caching the reference when the Activity is destroyed,
however the page is reloaded on orientation changes as well (so my image is rendered and immediately
cleared).  In-fact if you were to take a picture in Landscape or show an image from the library
and then changed the orientation the images are removed, due to page reload.
> Here is my code to at least get past the NPE: (Still would like a fix for the page reload
on orientation changes)
> public class DeanTest2 extends DroidGap
> {
>   private static final Object CALLBACK_LOCK = new Object();
>   private static CordovaPlugin destroySafeActivityCallback = null;
> 	
>   @Override
>   public void onCreate(Bundle savedInstanceState)
>   {
>     super.onCreate(savedInstanceState);
>     synchronized(CALLBACK_LOCK) {
>       if (destroySafeActivityCallback != null) {
>         activityResultCallback = destroySafeActivityCallback;
>         destroySafeActivityCallback = null;
>       }
>     }
>         
>     super.loadUrl(Config.getStartUrl());
>   }
>     
>   @Override
>   public void onDestroy() {
>     if (activityResultCallback != null) {
>       synchronized(CALLBACK_LOCK) {
>         destroySafeActivityCallback = activityResultCallback;
>       }
>     }
>     	
>     super.onDestroy();
>   }
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message