terikon / cordova-plugin-photo-library

Maintainer needed. Please contact if you're using this library in your project
MIT License
149 stars 295 forks source link

Plugin is not working in Android #44

Closed cassio-rossi closed 7 years ago

cassio-rossi commented 7 years ago

Dear Sirs. I added the plugin, following the instructions on the README file from MASTER but when I run on Android, the App, it crashed, saying that the App has stopped working.

I tried to read the logcat file, but can't understand or find where the problem could be.

Can someone instruct me how to make it work in Android ? Under iOS is working perfectly. Can someone instruct me how to find the lines on logcat to help find the problem ?

Environment:

Thanks. Cassio

cassio-rossi commented 7 years ago

UPDATE: I re-create the project and re-installed all plugins. I found that there is a conflict with the cordova plugin phonegap-plugin-push.

Any ideas ?

Cassio

cassio-rossi commented 7 years ago

Update 2: Now, the error I'm getting is: Expected file scheme in URI: http://...

Please, help !!!!

cassio-rossi commented 7 years ago

Update 3: here is the image with the message, which occurs after giving permission to access the Gallery and the code.

screenshot_1490128778

// Ionic Starter App

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
angular.module('starter', ['ionic'])

.run(function($ionicPlatform, $rootScope) {
  $ionicPlatform.ready(function() {
    if(window.cordova && window.cordova.plugins.Keyboard) {
      // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
      // for form inputs)
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);

      // Don't remove this line unless you know what you are doing. It stops the viewport
      // from snapping when text inputs are focused. Ionic handles this internally for
      // a much nicer keyboard experience.
      cordova.plugins.Keyboard.disableScroll(true);
    }
    if(window.StatusBar) {
      StatusBar.styleDefault();
    }

    $rootScope.save = function() {
      var url = 'https://s-media-cache-ak0.pinimg.com/originals/83/90/0a/83900a5b6d403ddbfd4e843ea70828f4.jpg'; // url can also be dataURL, but giving it a file path is much faster
      var album = 'MyAppName';
      cordova.plugins.photoLibrary.saveImage(url, album, function (libraryItem) {
        alert('ok');
      }, function (err) {
        alert(err);
        cordova.plugins.photoLibrary.requestAuthorization(
          function () {
          // User gave us permission to his library, retry reading it!
            $rootScope.save();
          },
          function (err) {
          // User denied the access
            alert('not authorized');
          }, // if options not provided, defaults to {read: true}.
          {
            read: true,
            write: true
          }
        );
      });
    };
    $rootScope.save();
  });
})

Please, anyone, help !!!!!

cassio-rossi commented 7 years ago

Update 4:

Manage to fix the URI Scheme:

and replace:

File sourceFile = new File(new URI(url));
is = new FileInputStream(sourceFile);

with

is = new URL(url).openStream();

Now I'm going to check the conflict with the push plugin.

viskin commented 7 years ago

Cool. If your change makes it possible to use remote urls with photoLibrary.saveImage, I will add it to next version. Does photoLibrary.saveImage with https:// urls works on iOS for you?

viskin commented 7 years ago

Ok, I tested your change and it enables remote urls on android. iOS worked without any change. So I added the change to 2.0.4. Thank you!