My question is that, if it is possible to get a variable from a .properties or .txt file. I need that in order to save the endPoint, the server IP address. That way, every time that the IP address is changed, all you need to do is change the IP on the file, instead of compile the code again and build the apk, and install it again on the device. Any tips will be welcome.
UPDATE
I've been trying to use this plugin :File , but with no sucess. I want to use readAsText(path,file) but all i get is undefined
import { File } from '#ionic-native/file/ngx';
constructor(
....
private file : File,
....
) { }
async test(){
this.promise = this.file.readAsText('file:///data/','ipAddress.txt');
await this.promise.then(value => {
console.log(value)
}).catch(error=> console.log("nao existe"))
}
And i'm getting the following error:
ERROR Error: Uncaught (in promise): FileError: {"code":1,"message":"NOT_FOUND_ERR"}
UPDATE
Problem Solved. I was trying to acess to the internal storage, and the document was on the external storage. Make sure you use URI, path on android are different from computer. You need URI.
file:///storage/emulated/0/Android/data/
I called the method right on, when device's ready on app.component.ts
ngOnInit() {
.....
this.initializeApp();
}
initializeApp() {
this.platform.ready().then(() => {
this.api.getURL();
.....
});
}
Hope i can help the next with the same problem I had.
Related
I created an app with expo where some report in xlsx is generated in a server and then downloaded to the Download folder in Android. I want to "open" the file after it was downloaded by using another app with the open with native modal. I tried the following:
static openFile = async (asset, contentType) => {
return IntentLauncher.startActivityAsync('android.intent.action.VIEW', {
data: asset.uri,
type: contentType,
});
};
(contentType is currently receiving '*/*') but it fails everytime with the following error:
Encountered an exception while calling native method: Exception occurred while executing exported method startActivity on module ExpoIntentLauncher: file:///storage/emulated/0/Download/report-10010654-20210304061930069176.xlsx exposed beyond app through Intent.getData()
One solution is using the Sharing library, but I'm not overjoyed with it. Is there any way to make it work without ejecting from the managed flow?
I had a similar problem a month ago, I think it happens when startActivityAsync is called multiple times, my solution was to wrap my code in a try statement:
const data = await getContentUriAsync(uri)
try {
await startActivityAsync('android.intent.action.VIEW', { data, flags: 1 })
} catch (error) {}
I'm totally new to Cordova and my current project happens to be implemented with that. I would need a way to read and list files inside a directory located at Internal storage/bap.
I've tried almost every possible way Google has given to me but without luck. If someone has any idea or could point me in the right direction, it would be really appreciated!
Edit
Managed to at least log the files with the following function, just had to be exact with the path and pass a full native path to the desired directory:
function listDir(path: string): any {
window.resolveLocalFileSystemURL(
path,
function(directory) {
var reader = directory.createReader();
reader.readEntries(
function(entries: any) {
console.log("entries inside listDir");
console.log(entries);
},
function(err: any) {
console.log(err);
}
);
},
function(err) {
console.log(err);
}
);
}
I'm developing a TrainingPlan React-Native App.
I want to store the data in Realm database.
When I create the default database file, it works great:
let realm=new Realm({path:'training.realm});
realm.write(() => {
realm.create('Training', { type: 'group', members: 12, });
});
It creates the training.realm in this path and works well (I/O): /data/data/com.realmtmp/files/training.realm
If I want to change tha path, where to create the training.realm file, I'm using this:
let realm=new Realm({path:'/storage/emulated/0/training.realm'});
realm.write(() => {
realm.create('Training', { type: 'group', members: 12, });
});
This creates the file, but shows "Error Read-only file system".
In this path I can create folders, copy files to there.
Why does this show read-only?
(Same error on Android Studio AVD and real USB connected mobile phone.)
Regards,
Imre
Anybody success to use the plugin cordovaFile & cordovaFileTransfer?
I have failed to understand and failed miserably execution. Case wants to make the upload and download controller. Each tested via the browser, it always appears File / FileTransfer is not defined in Firebug. When I made to console.log as:
console.log($cordovaFile); or
console.log($cordovaFileTransfer); or
console.log($cordovaFileTransfer.download); or
console.log($cordovaFileTransfer.upload);
Its return true, form of the {object}.
But when I call their methods included parameters, for example:
$cordovaFileTransfer.download (urlServer, fileTarget, {}, true);
Direct emerge error: FileTransfer is not defined.
I tried to move the download function to the Service, and then Controller call the function (the umpteenth time search results on google). The result is just the same, the above error.
Because there are user in some forum said should / could only be tested through the device, finally I try to upload ionic.io & I sync via APL ionic view on my Smartphone. But the result is NOTHING.
I tried to improvise a little, try method checkDir / checkFile as follows:
.controller('PhotoCtrl', function($scope, $cordovaFile) {
$scope.downpic = function(){
$cordovaFile.checkDir("/sdcard/storage/emulated/0/").then(function(result){
alert("wow");
}, function(err){
alert("eror");
});
}
})
It turns out alerts that appear "error", I try mutually value directory is as follows:
file///sdcard/storage/emulated/0/
file///storage/emulated/0/
/storage/emulated/0/
Just the same error alerts, the chain problem. My question :
What is the application of ionic cordova can access the internal
storage? (I only have the Mobile Internal Storage, without External
Storage);
I was looking for information about AndroidManifest.xml
uses-permission, the permission is only for external storage. Are
there any other analysis?
Please help, really newbie
Finally, I just got the clear solution from the link below :
https://www.thepolyglotdeveloper.com/2014/09/manage-files-in-android-and-ios-using-ionicframework/
I have a Cordova app that uses the ionic framework. I have many json data files that I put in the www/json folder in my app's file tree. I am using angularJS http calls to access them.
When I test my app in chrome (using "ionic serve" in the terminal) it works fine but when I test it on an android device(nexus 5 with Android 6.0 Marshmallow) it no longer works.
Sample code
function getBookNames() {
return $http.get("..\\bookfolder\\Books.json")
.then(function (data) {//if success than do
return data.data;
}, function (reason) {// if fail than do
// maybe tell the user what happened...
});
}
I have tried adding
var path = "";
if (ionic.Platform.isAndroid()) {
path = "\\android_asset\\www\\";
}
function getBookNames() {
return $http.get(path + "..\\bookfolder\\Books.json")
.then(function (data) {//if success than do
return data.data;
}, function (reason) {// if fail than do
// maybe tell the user what happened...
});
}
when I am debugging the app on my phone I get the following error.
GET file:///android_asset/bookfolder/Books.json net::ERR_FILE_NOT_FOUND
If anyone knows what I am doing wrong or of a better way to access local .json files please let me know. Thanks!
Use slash / character, not backslash \. Also, put bookfolder inside /android_asset/www
$http
.get('/android_asset/www/bookfolder/books.json')
.then(function(response){ return response.data });