Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Memory Info component for Web Runtime widgets

From Wiki
Jump to: navigation, search
Article Metadata
Article
Created: jzferreira (14 Jul 2009)
Last edited: hamishwillee (07 May 2012)


Contents

Description

Memory Info component is a simple component that helps you to retrieve information about memory. How can it help you? For example, you have a widget and you save many information in the device, but before you save this information, it's necessary to check if the device has free space.

With this component you can check if you have free space from device and memory card (if it exists); besides that, you can retrieve the critical memory too.

How to use

It's simple to use this component, it's only necessary to import from html and use the object MemoryInformation.

  • MemoryInformation.getListDrives: this function retrieves all drivers that are in your phone and builds an array (listDrivers). If no drive is found, the first element in listDrivers[0] is the string 'none';
  • MemoryInformation.getDriveInfo: you can retrive information about all drivers from listDrivers.
    • Drive
    • TotalSpace
    • FreeSpace
    • CriticalSpace
    • MediaType
    • BatteryState
    • DriveName
  • MemoryInformation.getCriticalMemory: the information about critical memory;
  • MemoryInformation.getMemoryCard: the information about memory card;

Code Component

MemoryInfo.js is the file where the code should be found.

/**
* @author Javier Zambrano Ferreira
*/

 
var MemoryInformation = {
 
listDrivers: [], //list of drivers;
driversInfo: [], //information about drivers;
criticalMemory: '',
memoryCard: 0,
 
/**
* Build an array with have all drivers;
*/

getListDrives: function(){
 
try {
 
var so = device.getServiceObject("Service.SysInfo", "ISysInfo");
 
var criteria = {};
criteria.Entity = 'Memory';
criteria.Key = 'ListDrives';
 
var result = so.ISysInfo.GetInfo(criteria);
 
if (result.ErrorCode === 0) {
MemoryInformations.listDrivers = result.ReturnValue.DriveList;
}
else {
MemoryInformations.listDrivers[0] = result.ErrorCode;
}
 
}
catch (ExceptionListDrives) {
alert("Exception List Drivers: " + ExceptionListDrives);
MemoryInformation.listDrivers[0] = 'none';
}
 
},
/**
* Get MemoryInformation from all drivers;
*/

getDriveInfo: function(){
 
var driversInfo = [];
 
try {
 
var so = device.getServiceObject("Service.SysInfo", "ISysInfo");
 
var drivers = MemoryInformation.listDrivers;
 
for (var index = 0; index < drivers.length; index++) {
 
var SystemData = {};
SystemData.Drive = drivers[index];
 
var criteria = {};
criteria.Entity = 'Memory';
criteria.Key = 'DriveInfo';
criteria.SystemData = SystemData;
 
var result = so.ISysInfo.GetInfo(criteria);
 
if (result.ErrorCode === 0) {
 
var totalSpace = parseInt(result.ReturnValue.TotalSpace,10);
var freeSpace = parseInt(result.ReturnValue.FreeSpace,10);
 
driversInfo[index] = {
Drive: result.ReturnValue.Drive,
TotalSpace: totalSpace,
FreeSpace: freeSpace,
CriticalSpace: result.ReturnValue.CriticalSpace,
MediaType: result.ReturnValue.MediaType,
BatteryState: result.ReturnValue.BatteryState,
DriveName: result.ReturnValue.DriveName
};
 
}
else {
driversInfo[0] = result.ErrorCode;
}
 
}
 
MemoryInformation.driversInfo = driversInfo;
 
}
catch (ExceptionListDrives) {
alert("Exception Driver Info: " + ExceptionListDrives);
MemoryInformations.driversInfo[0] = 'none';
}
 
 
},
getCriticalMemory: function(drive){
 
var infomemory = '';
 
try {
 
var so = device.getServiceObject("Service.SysInfo", "ISysInfo");
 
 
var SystemData = {};
SystemData.Drive = drive;
 
var criteria = {};
criteria.Entity = 'Memory';
criteria.Key = 'CriticalMemory';
criteria.SystemData = SystemData;
 
 
var result = so.ISysInfo.GetNotification(criteria, function(transId, eventCode, result){
if (result.ErrorCode === 0) {
 
infomemory = result.ReturnValue.StringData;
 
}
else {
infomemory = result.ErrorCode;
}
 
MemoryInformation.criticalMemory = infomemory;
});
 
}
catch (ExceptionCriticalMemory) {
alert("Exception Critical Memory: " + ExceptionCriticalMemory);
MemoryInformation.criticalMemory = 'none';
}
 
},
getMemoryCard: function(){
 
try {
 
var so = device.getServiceObject("Service.SysInfo", "ISysInfo");
 
var criteria = {};
criteria.Entity = 'Memory';
criteria.Key = 'MemoryCard';
 
var result = so.ISysInfo.GetInfo(criteria);
 
if (result.ErrorCode === 0) {
MemoryInformation.memoryCard = result.ReturnValue.Status;
}
else {
MemoryInformations.memoryCard = result.ErrorCode;
}
 
}
catch (ExceptionListDrives) {
alert("Exception List Drivers: " + ExceptionListDrives);
MemoryInformation.memoryCard = 'none';
}
 
}
 
};

Conclusion

Performing tasks such as reading the information about the available memory is a tedious task and this component aims to ease this difficulty.

This page was last modified on 7 May 2012, at 05:37.
204 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×