0

I'm trying load an image dynamically from the web in PhoneGap (2.8.1) - Android 4.2.2. The code for this is as follows ('photo' is the id of an "img" tag):

    var imageSource = "http://placekitten.com/g/400/400";
    $('#photo').load(function(){
                            console.log("Image Path : "+imageSource);
                            image_loaded = 1;
                        }
            )
        .attr("src", imageSource)
        .error(
            function(){
                image_loaded = -1;
                alert('Image failed to load');
                var thisImg = this;
                setTimeout(function(){
                        if ( ! thisImg.complete ) {
                            alert('Process not complete yet');
                            $(thisImg).attr("src", imageSource);
                        }
                    },
                    30000
                );
            });

However, the code fails to load it. This is a bit strange because, the same code, with the same phonegap version, works perfectly fine in Android 2.2, but somehow it just falls in the "error" section in Android 3.x and 4.x!

On careful comparison of the "LogCat"s of Android 2.2 and 4.2.2 devices, it is evident that there's a message in the latter case, which reads:

    "Unkonwn chromium error:  - 6"

Have read several posts and attempted to set various access permissions in XML etc, attempted replacing Phonegap libraries with the higher version (2.9.1), but to no avail. Some reference questions on StackOverflow:

jquery.load() is not working on phonegap 3.0.0

Will jQuery .load() Work On PhoneGap?

For Android 3.x and 4.x, if I may please also add that the console.log() function under the $("#photo").load() is not even hit at all and the code right away lands on the "alert" in the "error" section.

Am I missing something obvious please? Or if there's any trick that can be tried?

Thanks a lot!

Community
  • 1
  • 1
Dhruv Saxena
  • 1,336
  • 2
  • 12
  • 29

1 Answers1

0

Well, the solution to this was completely unexpected.

Having researched a lot on the internet, the general sense that prevailed was that (perhaps) the only stable versions of Phonegap so far have been Phonegap 2.4.0 and Phonegap 2.5.0

I merely replaced the Phonegap library from Phonegap 2.8.1 to Phonegap 2.4.0 and everything now works fine on all the Android versions! I didn't have to change the HTML, jQuery or Android code one bit.

Indeed it sounds strange, but that's what it is. Don't think I've had to compromise on any other Phonegap functionality - so far - due to this deliberate 'downgrade'.

Thanks.

Dhruv Saxena
  • 1,336
  • 2
  • 12
  • 29