Reputation: 2158
I've been trying to install a custom cordova plugin (not available in the ngCordova library) in my Ionic project which will enable me to take a picture with no user input on Android:
I've been struggling with integrating this properly into my Ionic App, and am not sure how to:
a) Implement deviceready as per Cordova documentation:
document.addEventListener("deviceready", yourCallbackFunction, false);
b) Call function within Ionic without app crashing.
Upvotes: 0
Views: 349
Reputation: 879
Instead of deviceready
on the device, try using ionic's built in ready method, that fires when Cordova, Angular, and Ionic are ready.
ionic.Platform.ready(function(){
//do plugin stuff here
});
http://ionicframework.com/docs/api/utility/ionic.Platform/
Upvotes: 1
Reputation: 2158
I was having some struggles with understanding these issues as a beginner:
a) I utilized $ionicPlatform.ready instead. This was placed inside of my controller which had $ionicPlatform dependency injected. See below:
.controller('captureCtrl',['$scope', '$ionicPlatform', function($scope, $ionicPlatform){
$ionicPlatform.ready(function() {
//function call in here
})
}]);
As per the statement below, it should work just as well.
The ionicPlatform.ready event is called when Cordova's deviceready event fires.
b) This plugin had an issue in the CameraSurfacePreview.java as per the github issues page. Commenting out the line (94) stopped the device from crashing.
Besides this, the plugin only worked after rebuilding the Android platform:
> ionic platform rm android
> ionic platform add android
> ionic build android
I'm not sure why that is. Please feel free to comment for those who know more.
Upvotes: 0