Check if the SD Card is available - blackberry

My application need to download some files to cache.
but i wanted to check if the user have SDcard installed so i can save files there instead of the device memory. i used this code :
String SDexist = "file:///SDCard/";
fconnSD = (FileConnection) Connector.open(SDexist,Connector.READ);
if(!fconnSD.exists())
{
FileDire = "file:///store/home/user/catch/";
} else
{
FileDire = "file:///SDCard/BlackBerry/catch/";
}
but it's not working, it allways looks for SD card and not saving files in device memory even if the SD card is not available. Any ideas?

Solved, i used FileSystemRegistry.listRoots();
And read root elemnts, if sdcard exsits then the SD card should be installed.

Related

How to download a file in iOS (Ionic 2/3)?

I am trying to download a file and save that file in iOS. I am using ionic-native-file plugin to achieve this. The file has been download but i could not find that file in the device.
filewrite = (): void => {
let transfer = this.fileTransfer.create();
let path = "";
let dir_name = 'Download';
let file_name = "Sample.pdf";
if (this.platform.is('ios')) {
this.platform.ready().then(() => {
path = this.file.documentsDirectory;
this.file.writeFile(path,file_name,this.pdfSrc).then((entry) => {
this.showAlert("download completed");
}, (error) => {
this.showAlert("Download Failed.");
}).catch(err=>{
this.showAlert("Download Failed catch.");
this.showAlert(err.message);
});
}
)
}
};
Download completed alert shows and the downloaded path is:
file:///var/mobile/Containers/Data/Application/6DE22F30-5806-4393-830A-14C8A1F320BE/Library/Cloud/Sample.pdf
But i could not find that location in the device. Then, i google and saw here.
cordova.file.documentsDirectory - Files private to the app, but that
are meaningful to other application (e.g. Office files). Note that for
OSX this is the user's ~/Documents directory. (iOS, OSX)
So, i can't see the file actually as it is private to the application. Then i saw in the same link:
So, i tried with the both preference in my config.xml but nothing happened.
Is there any approach to download the file iOS or to dropbox or anywhere else?
I've struggled to find the right directory to save to on different platforms with this cordova plugin too. I landed on using file.externalRootDirectory on Android, and file.cacheDirectory on iOS.
The right location likely depends on what you intend to do with the file. In my case I just needed it stored short-term so I can open it using the user's native PDF reader.

Clear ios app storage data?

So I'm able to delete image cache's, but is there a way to delete files in the storage for the app? For example, if you go to Settings > General > Storage And iCloud Usage > Manage Storage and then find your app. I want to clear this data, because it keeps building up. Any insight on this?
This is what I currently have:
var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
var cache = System.IO.Path.Combine(documents, ".config", ".isolated-storage", "ImageLoaderCache");
foreach (var file in System.IO.Directory.GetFiles(cache))
{
//older than or 3 days, delete
DateTime fileCreationDate = System.IO.File.GetCreationTime(file);
if ((DateTime.Now - fileCreationDate).Days >= 3)
{
System.IO.File.Delete(file);
}
}
Instead of storing cached images in Document (<Application_Home>/Documents) folder, Store it in Cache (<Application_Home>/Library/Caches) folder.
According to iOS data Storer Guidelines If you are storing something in document directory, it means you want to backup it on iCloud.
so when data is store in document directory- its getting uploaded to iCloud. and thats why its displaying in iCloud storage.

Xamarin Forms CircleImage with source from file

I'm using a plugin CircleImage from https://github.com/jamesmontemagno/Xamarin.Plugins/tree/master/ImageCircle
I'm using it in a listview. I noticed it's working fine with image from a url but I can't find a way to show an image from embedded resources or files. Could you explain me how do that?
Thank you in advance!
Is the image in your Resources folder on iOS and Android platforms and in the root on Windows Phone?
You probably want to use the following to set the source of a local image:
Source = ImageSource.FromFile("someimage.png")
Or you might even try:
Source = (FileImageSource)ImageSource.FromFile("someimage.png")
Also be careful with upper and lower case file names. I suggest making everything lower case. The iOS simulator will not care about casing (since Macs do not care), but a real iOS device will care.
For other developers I write and describe my solution for that. I have a MVVM model. In this model there is property
ImageSource image
when I fill the data in the model (r in the example) I verify if taking an embedded image or an image from file system
if (images.Count == 0) {
// from file
r.Image = ImageSource.FromFile ("GenericImageFromResource.png");
} else {
// get the file image from file system
//(required an implementation for each platform)
r.Image = ImageFinder.GetImage (images.First().FileName);
}

How to move/copy a file from one one location to the other using phonegap

I am using the Phonegap File API but am having trouble copying a file from one location to the other.
my targeted device is iOS(ipad)
my iOS version is 9.2.1
I am working on windows platform
I am using phonegap build
my requirement :
I am capturing a video and its getting saved in some temp folder by default here is the location where its getting saved (/private/var/mobile/Containers/Data/Application/2183897E-3660-4145-A822-76F5B763E48D/tmp/capture-T0x17e7cae0.tmp.avqBi2/capturedvideo.MOV)
So I just want to move this (capturedvideo.MOV) video to photo album location in my ipad
This is my code which i am trying to make it work.
function success(entry) {
console.log("New Path: " + entry.fullPath);
}
function fail(error) {
alert(error.code);
}
function moveDir(entry) {
var parent = document.getElementById('parent').value,
parentName = parent.substring(parent.lastIndexOf('/')+1),
newName = document.getElementById('newName').value,
parentEntry = new DirectoryEntry(parentName, parent);
// move the directory to a new directory and rename it
entry.moveTo(saveToPhotoAlbum, newName, success, fail);
}
Any help or working examples would be great.
Thanks
Nik`
This is simply not possible on iOS, because Apple does not allow to move videos, images or any other files out of the app sandbox to other folders. The reason that the standard-camera on the iPad/iPhone is able to place pictures there is simply because this is a built-in feature that has special permissions which your third-party app will not be able to get.
This is of course only true as long as the device is not jailbroken.
For more infos, especially concerning the file-system layout and what you are allowed to store, you should take a look at the cordova-file-plugin Readme on Github:https://github.com/apache/cordova-plugin-file

Xna Windows Phone 7 Saving Game Data

Im trying to find out how to save highscore data to the isolated storage on windows phone. I have searched numerous things and have found nothing working. Anyone know how I can do this?
The following answer was taken from this MSDN entry:
http://msdn.microsoft.com/en-us/library/ff604992.aspx
XNA Game Studio 4.0 Refresh does not provide access to writeable
storage on Windows Phone. To access such storage, you'll need to use
classes from the System.IO.IsolatedStorage namespace.
For Windows Phone projects, Visual Studio automatically adds the
assembly containing System.IO.IsolatedStorage to your project. There
is no need to add any additional references to your project.
Examples for writing data to the Isolated storage:
protected override void OnExiting(object sender, System.EventArgs args)
{
// Save the game state (in this case, the high score).
IsolatedStorageFile savegameStorage = IsolatedStorageFile.GetUserStoreForApplication();
// open isolated storage, and write the savefile.
IsolatedStorageFileStream fs = null;
using (fs = savegameStorage.CreateFile(SAVEFILENAME))
{
if (fs != null)
{
// just overwrite the existing info for this example.
byte[] bytes = System.BitConverter.GetBytes(highScore);
fs.Write(bytes, 0, bytes.Length);
}
}
base.OnExiting(sender, args);
}

Resources