cordova unzip files from www folder - android

I'm trying to unzip files from www folder to external location using zip plugin.
I assign external data directory to a variable folder when application start.
window.resolveLocalFileSystemURL(cordova.file.externalDataDirectory, function (folder) {
$filex.folder= folder;
});
then i call dataUnzip.
dataUnzip:function(){
var wwwPath = window.location.pathname;
var basePath = 'file://'+ wwwPath.substring(0,wwwPath.length-10);
window.resolveLocalFileSystemURL(basePath+'ex.zip',
function(fileDB){
alert('success! database was found')
unzipFiles(fileDB);
},
function(){
alert('failure! database was not found')
});
function unzipFiles(fileDB){
zip.unzip(fileDB,$filex.folder.nativeURL + "",
function (a) {
alert('Zip decompressed successfully' + a);
}
);
}
}
but i always get output as Zip decompressed successfully -1.-1 means unzip has failed.it works if i unzip .zip from external location like externalDataDirectory .but i want to unzip a file exist in www directory.
is there any way to get descriptive error ?instead of -1.and what could be the reason for unzip failure ?
here is a screenshot of www folder

Read here for documentation about file permissions etc
External Data Directory is not available on all platforms, what platform are you testing on?
Can you not just store the files unzipped in your application directory?
Otherwise, you may need to use different locations for each platform and use the merges folder.

Related

Flutter: How to create a folder at the root of the directory, i.e, not under any directory

I am developing a file based application through flutter.
I can create a folder through getApplicationDocumentsDirectory() which gives the path to write files. But it cannot be seen in the files Explorer
I then created the folder through getExternalStorageDirectory() , which can be seen in the files explorer. But I want it to be created in the root.
You may have seen whatsapp folder in the root directory. I also want the same thing. I have tried the following:
Directory('FolderName').create()
But it gives the error saying 'read only os '
Is there a way to do it through flutter ?
You can do it this way:
String folderName = "My New Downloads";
var path = "storage/emulated/0/$folderName";
await new Directory(path).create();

In a react-native android project,How to copy a folder from assets to the DocumentDirectoryPath?

I am using a react-native project in which,I want to copy the contents of a certain folder in assets inside android to RNFS.DocumentDirectoryPath. How can this be performed?
I have used the attribute copyFileAssets().
copyfile() {
RNFS.copyFileAssets('/ICF-Package', RNFS.DocumentDirectoryPath + '/ICFPackage').then((result) => console.log('DONE')).catch((error) => console.log(error, 'ERROR'));
};
I'm getting the following error:
Error: Asset '/ICF-Package' could not be opened
Your code is correct. However, it looks like /ICF-Package is a folder or something, but not a file. copyFileAssets can only copy files, but no folders (and its content)

Assets Folder Not Including HTML Files In NativeScript Android Build

I am trying to display a local html file with JS and CSS and PNG images referenced by it. I put the files into my assets folder of a NativeScript x Angular app for Android. When I run tns run android --bundle and the app gets built - the assets folder does not include the html. Folder structure goes from assets > index.html (and index.html references the other files).
Is there a certain place or way I need to include html files so they get included in the build?
You must update CopyWebpackPlugin in your webpack.config.js to include the asset folder
// Copy assets to out dir. Add your own globs as needed.
new CopyWebpackPlugin([
{ from: "fonts/**" },
{ from: "**/*.jpg" },
{ from: "**/*.png" },
{ from: "assets/**" }, // Add your asset folder path like this
], { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }),

Deleting file from internal storage

How do I delete a file or folder on the internal storage in android with Delphi for android
You should use the TFile and TDirectory classes in the System.IOUtils unit.
For example:
TDirectory.Delete(<YOUR DIR PATH>);
or
TFile.Delete(<YOUR FILE PATH>);
Look in Embarcadero's documentation to get the right path of your files and folders on the various platforms:
Standard RTL Path Functions across the Supported Target Platforms
Referred from :
https://stackoverflow.com/a/27047502/5193608
https://stackoverflow.com/a/3554949/5193608
Main Part from both links:
You should always delete files that you no longer need. The most straightforward way to delete a file is to have the opened file reference call delete() on itself.
myFile.delete();
If the file is saved on internal storage, you can also ask the Context to locate and delete a file by calling deleteFile():
myContext.deleteFile(fileName);
Note: When the user uninstalls your app, the Android system deletes the following: All files you saved on internal storage All files you saved on external storage using getExternalFilesDir(). However, you should manually delete all cached files created with getCacheDir() on a regular basis and also regularly delete other files you no longer need.
Source : http://developer.android.com/training/basics/data-storage/files.html
Directly you can do is :
File dir = getFilesDir();
File file = new File(dir, "my_filename");
boolean deleted = file.delete();
Hope,it helps!

Android unity3d image path

I am trying to get an instance of an image in Unity that is in:
/assets/texture/image.png
Here is what I did:
path = Application.persistentDataPath;
path2 = Application.dataPath;
path3 = Application.streamingAssetsPath;
iTextSharp.text.Image imageHeader = iTextSharp.text.Image.GetInstance("jar:file://" + path2 + "!/assets/texture/image.png");
I did try with all the paths, and I am getting:
NotSupportedException:
jar:file:/data/app/com.myapk!/assets/texture/image.png.
Any help?
To access a file in the assets folder of your apk:
String path = getAssets() + "/texture/image.png";
iTextSharp.text.Image imageHeader = iTextSharp.text.Image.GetInstance(path);
The path should be something like:
file:///android_asset/texture/image.png
EDIT: Can't use getAssets in Unity - Then there will not be a direct system-mounted file path for files in the assets folder.
What I usually do for C++/NDK applications with graphical assets is to decompress the assets directory to the SDCard to have a direct path access. On first launch of the app, you extract your assets folder to /mnt/sdcard (getExternalStorageDirectory) then use that. Otherwise I have no Idea how to do it in Unity directly, but there must be something.
If you want to make this easy on yourself, put your texture in the Resources/ folder and use Resources.Load to load it. Or put it in StreamingAssets/ and use the WWW class to load if from the jar file.

Categories

Resources