Camera plugin + cordova social sharing

1k Views Asked by At

I'm using the camera plugin to take a photo, and I want to share that photo with the cordova social sharing plugin, but I don't know how...

the camera works fine, and shows me the photo i'd taken

ionicApp.controller("functions", function($scope, $rootScope, $cordovaCamera) {

$rootScope.takePicture = function() {
    var options = { 
        quality : 75, 
        destinationType : Camera.DestinationType.DATA_URL, 
        sourceType : Camera.PictureSourceType.CAMERA, 
        allowEdit : true,
        encodingType: Camera.EncodingType.JPEG,
        targetWidth: 300,
        targetHeight: 300,
        popoverOptions: CameraPopoverOptions,
        saveToPhotoAlbum: false
    };

    $cordovaCamera.getPicture(options).then(function(imageData) {
        var image = document.getElementById('myImage');
        $rootScope.imgURI = "data:image/jpeg;base64," + imageData;
    }, function(err) {
        // An error occured. Show a message to the user
    });
}

});

ionicApp.controller("share", function($scope, $cordovaSocialSharing) {

$scope.shareAnywhere = function() {
    $cordovaSocialSharing.share("#DSTRY_CAM", "#DSTRY_CAM", "www/imagefile.png", "http://DSTRYCAM.COM");
}

});

but how i can put the photo taken before in this share function? I believe is changing the "www/imagefile.png" but I don't know how.

thank you, and sorry for my bad english

1

There are 1 best solutions below

3
On

Please refer to this GitHub link.

https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin

This cordova plugin is the reflection of $cordovaSocialSharing that you are actually using with ngCordova. You already got your base64 image URL using $cordovaCamera. So you can now share your image using share() function of $cordovaSocialSharing.

For example,

$cordovaSocialSharing
    .share(null,"filename.jpg", $rootScope.imgURI, null)
    .then(function(result) {
      // success callback
    }, function(err) {
      // error callback
    });

This will let you to to share your picture (under the filename of "filename.jpg") by opening built-in share dialog in both iOS and Android. Pretty simple.

EDIT: You also need to include $rootScope in your controller.