PhoneGap app is unresponsive on Android

2019-07-19 02:36发布

问题:

I created a simple PhoneGap application that, right now, just takes a picture when you tap a button and then displays the picture in an image on the same page. I've built both iOS and Android versions, and the iOS version works fine. The Android version, on the other hand, highlights the button but never switches to a camera activity. What could be the problem?

My first thought was that the problem is in the Javascript code in my index.html file. So, I completely replaced the contents of my index.html with the "Full Example" from the PhoneGap API Camera reference page. This page displays four buttons, each of which triggers a Javascript function that uses PhoneGap to acquire an image in one way or another. The app builds without errors and starts up on my test device (HTC Evo 4G). Once again, however, tapping any of the buttons causes that button to highlight, but nothing else happens.

I'm using a recently downloaded PhoneGap 0.95, the latest Android SDK (downloaded and installed two days ago), and Eclipse with the ADT plugin.

Can anyone give me some ideas as to how to start debugging this?

Edit: For what it's worth, I set up my Android project according to the steps in the PhoneGap Get Started Guide for Android. I modified the AndroidManifest.xml file according to the directions there and using exactly the text from the directions, so the first line after the <supports-screens ... /> block is:

<uses-permission android:name="android.permission.CAMERA" />

回答1:

Caleb>

I was stumbled by the exact same problem with phonegap android + HTC EVO 4G.

Maybe you got this figured out already. Just in case,

The root cause of the default sample app NOT working is incorrect url for the javascript src in the index.html file generated in the example_android folder.

  -- PROBLEM: I noticed that index.html in the example_android folder  is linking to a js file don't exist. 
      type="text/javascript" charset="utf-8" src="phonegap.0.9.5.min.js"
  changed it to    
      type="text/javascript" charset="utf-8" src="phonegap.0.9.5.js"

After I removed ".min" from the src attrib, rebuild android app and redeploy to my android phone. Everything starts working fine.



回答2:

Try reducing the Resolution of the saved camera image by running the Camera app and selecting the settings button.

The camera button in the PhoneGap example app usually crashed for me until I reduced the resolution.

I haven't debugged it, but I'm guessing there is a memory overflow somewhere with the default Evo camera resolution (5M on my phone)



回答3:

Try 'uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"' in your manifest file and use 'destinationType: Camera.DestinationType.FILE_URI' for phonegap's getPicture call. I had the same problem and adding WRITE_EXTERNAL_STORAGE permission worked for me.