Phonegap - Can't get Camera to come up at all - android

I've read every question both here and on Google and can't for the life of me figure this one out. I'm simply trying to use Phonegap to take a picture and store the URI. I'm trying to use the example from the docs here. Here's the snippet where I'm trying to open the camera.
this.getPicture = function() {
navigator.camera.getPicture(self.onBackSuccess, self.onFail, {
quality: 20,
destinationType: Camera.DestinationType.FILE_URI
});
};
What I've already checked/verified
Phonegap/Cordova itself is installed and working fine. I can build my app with no problems.
navigator.camera above is definitely defined. I can follow the code down and the "getPicture" function is being called, but that doesn't pull up the Camera, either on the device, ADB emulator, or Ripple browser emulator.
Neither my success nor my error callback are ever being called. However, when I look at those variables in the getPicture function, I can see the appropriate function stored in those variables.
I have installed the Phonegap camera plugin. When I run phonegap local plugin list, one of the results is org.apache.cordova.camera 0.3.4 "Camera"
My config.xml file contains both the lines <feature name="http://api.phonegap.com/1.0/camera"/> and <gap:plugin name="org.apache.cordova.camera" />. Not sure if that's relevant, since the plugin is already installed.
My AndroidManifest.xml file contains the lines <uses-permission android:name="android.permission.CAMERA" />, <uses-feature android:name="android.hardware.camera" />, and <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />.
When I click on the button that calls this function, it prints out this:
[20,1,1,-1,-1,0,0,false,false,false,null,0]
which is the array of cameraOptions that gets generated/used by the camera.getPicture function.
Everything I've been able to find just takes for granted the fact that calling navigator.camera.getPicture(success, failure, options); is going to open the camera, so there doesn't seem to be much info on solving my particular problem. Any pointers here would be much appreciated.
Edit: I am seeing an error in the console that looks like it may be related:
Could not find cordova.js script tag. Plugin loading may fail.
Edit: I don't think my last edit is relevant. That has to do with the loading of the plugin files themselves, and I can see the Camera.js file in the plugins folder when I load my app. I can put a breakpoint in the cameraExport.getPhoto function and it does go in there. Then it calls
exec(successCallback, errorCallback, "Camera", "takePicture", args);
which prints out the array I mentioned before and does nothing else.

without seeing all of your code, my guess is that the use of this. and self. is causing the issue. Try something like this:
function getPicture() {
navigator.camera.getPicture(onBackSuccess, onFail, {
quality: 20,
destinationType: Camera.DestinationType.FILE_URI
});
};
function onBackSuccess() {
//some code
}
function onFail() {
//some code
}

Related

How To Access Files on Android Device Using Ionic Framework

I was working through the Ionic tutorial for using the Cordova Camera API.
http://learn.ionicframework.com/formulas/cordova-camera/
Far as I can tell everything is working correctly with the Camera API functions, but I cannot get my image to display back into the view.
I am able to return a file URI, but when I attempt to put it to the ng-src I get nothing in the view. I am assuming that the application/code cannot access the file location?
My config:
.config(function($stateProvider, $urlRouterProvider, $compileProvider) {
$compileProvider.imgSrcSanitizationWhitelist(/^\s*(https?|ftp|file|blob|content):|data:image\//);
...
The function in my controller:
$scope.getPhoto = function() {
Camera.getPicture().then(function(imageURI) {
console.log(imageURI);
$scope.cameraPic = imageURI;
}, function(err) {
$scope.cameraPic = "error";
console.err(err);
});
};
My view:
<ion-view>
<ion-content>
<div class="form-group padding-top">
<button class='button button-positive' data-ng-click="getPhoto()">
Take Photo
</button>
</div>
<div class="item item-image">
<img ng-src="{{cameraPic}}"/>
</div>
{{cameraPic}}
</ion-content>
</ion-view>
This appears to be the recommended method by the tutorial, and is also repeated on this thread. It sounds like it should work without using a Cordova file service implementation. I have found one such implementation which I guess I could use, but am I missing something here?
EDIT
Using chrome://inspect/#devices, I was able to look into the Webview/Console. I also rebuilt the project, just to see if that would help.
Definitely looking like a local file access issue.
As it turns out, this is an issue unique to using the emulator. I finally found the following on the ngCordova project:
NOTE: The camera API only works on a real device, and not in the
emulator.
Source: http://ngcordova.com/docs/plugins/camera/
This led me to test the code on an actual device using the USB debugger, where the file is accessed by the application and shared with the view as expected. This should be noted as a quirk of the library.

How to change Cordova camera plugin options

I am using cordova camera plugin. It works fine. But i have two problems. One of them; after i capture photo 2 buttons appear. Their names are "Save" and "Discard". I want to rename them with "confirm" and "Cancel". How can i do this? an other question; after Saving photo, my photo is turning. How can i block this?
Save/Discard - you can't do this in the Cordova Camera API presented to you.
You'd need to write your own plugin which uses a SurfaceView (more
detail here).
This is a known Android issue - it ignores the correctOrientation parameter - I believe however that it uploads the photo in the correct orientation. It just is not shown correctly.
after i add correctOrientation in my code, it shown phooto correctly.
navigator.camera.getPicture(photoCaptured,photoCapturedFail,
{
quality: 50,
destinationType: Camera.DestinationType.DATA_URL,
correctOrientation: true
});

Setup SoftKeyBoard Cordova Plugin

I would like to hide the softkeyboard onBlur.
Therefore, I found the softkeyboard plugin, and I suppose I installed it properly, following numerous threads posts.
However, this is the first time I use a plugin for cordova, and I get this error, so I guess something is missing:
Cannot read property 'SoftKeyBoard' of undefined
This refers to the js call in the html file:
var softkeyboard = window.cordova.plugins.SoftKeyBoard;
$('#keyboard').toggle(softkeyboard.show, softkeyboard.hide);
Does not window.cordova.plugins exist?
In order to set up the plugin, I did the following:
copy SoftKeyBoard.java to src/org.apache.cordova.plugins.SoftKeyBoard. I also rewrote the first line package accordingly.
copy the js file, and link it to the html file
add this line to res/xml/config.xml:
<plugin name="SoftKeyBoard" value="org.apache.cordova.plugins.SoftKeyBoard" />
In this XML, it's located in <cordova><plugins>
Is there anything else I should have done?

Displaying leadbolt ads on a phonegap android app

I’ve been trying without success to get leadbolt ads to show up on an android app I created using phonegap. This is what I’ve done so far:
I have created a notification ad on leadbolt.com, added references to LeadboltController.jar and LeadboltPhonegapPlugin.jar files contained in my projects libs folder.
Added the code below to my javascript file
var Leadbolt = function() { }
Leadbolt.prototype.load = function(data, successCallback, failureCallback) {
return PhoneGap.exec(successCallback, failureCallback, 'LeadboltPlugin', data[0], data);
};
PhoneGap.addConstructor(function() {
PhoneGap.addPlugin('leadbolt', new Leadbolt());
PluginManager.addService("LeadboltPlugin", "com.LeadboltPlugin.LeadboltPlugin");
});
Sometimes I insert the code below in my javascript file or index.html, either way I see no ads.
window.plugins.leadbolt.load(["*********"], null, null);
Am sure people must have gotten this to work on their apps. I would really appreciate any assistance offered.
Thanks alot.
Have you done this:
Open /res/xml/plugins.xml, add following lines:
<plugin name="LeadboltPlugin" value="com.LeadboltPlugin.LeadboltPlugin" />
<plugin name="LeadboltNotificationPlugin" value="com.LeadboltPlugin.LeadboltNotificationPlugin" />
Hey not sure if this helps, but I know Leadbolt released an update to their phonegap plugin and its available in the portal. They put all ads types in one plugin which is much more convenient to use. Have you tried that?
If still not working, you should write to their support with details and they will get an answer for you. I’ve done that and its been very helpful.

Passing in false to setBlockNetworkLoads() crashes my android app

What is the requirement to make use of this:
mMessageContentView = (WebView) findViewById(R.id.message_content);
mMessageContentView.getSettings().setBlockNetworkLoads(false);
Everytime I set setBlockNetworkLoads to false. My application crashes! If I set it to true, it works fine but my application can't load images over the network.
Is there something I need to do before hand before I can set it to false?
As correctly pointed out by Gallal - I should of made use of the logs. A quick command on dos:
adb logcat
Showed that my application was missing the internet permission in the manifest file. So adding the following to my android manifest solved my problem:
<uses-permission android:name="android.permission.INTERNET" />

Categories

Resources