Can't open up files


#1

Hey all,

fileOpener does not work with Android for me, whereas it does work on iOS. I tested it with the following devices:
Note 3 with KitKat
Note 4 with Lolipop

The error I get on those devices is attached to this message. (notice the null value thats associated with cordova.file.documentsDirectory)
Why does cordova.file.documentsDirectory turns null on Android?

Thanks in advance.

Here is my code:

	var url = Documents.download($stateParams.documentId, false);
    $scope.targetPath = cordova.file.documentsDirectory;
	var docName = $stateParams.documentName;
	docName = docName.split(".");
	$scope.fileName = $stateParams.documentId+"-"+$stateParams.modifiedTime+"."+docName[docName.length-1];
    var trustHosts = true
    var options = {};

	$cordovaFile.checkFile($scope.targetPath, $scope.fileName).catch(function(err) {
		// file was not saved earlier
		download();
	}).then(function(object) {
		if(angular.isObject(object)) {
			$scope.current = 100;
			// The file exists in cache
			openFile();
		}
	});

	function download()
	{
	    $cordovaFileTransfer.download(url, $scope.targetPath+$scope.fileName, options, trustHosts)
	      .then(openFile, failed, function (progress) {
	        $timeout(function () {
	          $scope.current = Math.ceil((progress.loaded / progress.total) * 100);
	        })
	      });
	}
	
	function failed(err)
	{
		err.body = err.body || "An unknown error occured";
		var dialog = $ionicPopup.show({
		    title: 'We feel embarrassed..',
		    subTitle: JSON.stringify(err.body),
		    scope: $scope,
		    buttons: [
		      { text: 'Cancel' },
		      {
		        text: '<b>Try Again</b>',
				onTap: function()
				{
					return "retry"
				}
		      }
		    ]
		});
		dialog.then(function(res) {
			if(res && res == 'retry') {
				download();
			}
			else {
				$ionicHistory.goBack()
			}
		})
	}
	
	function openFile()
	{
		$cordovaFileOpener2.open(
			$scope.targetPath+$scope.fileName
		).then(function() {
			console.info("FILE OPENED IN DEVICE SUCCESSFULLY (CACHE)")
		}, function(err) {
			failed();
		});
	}