我怎样才能找出一个通用的Windows Phone 8.1应用程序的avaible自由空间 [英] How I can find out the avaible free space in a universal Windows Phone 8.1 App

查看:162
本文介绍了我怎样才能找出一个通用的Windows Phone 8.1应用程序的avaible自由空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

没有人知道如何访问一个通用的Windows Phone 8.1应用程序的avaible自由空间?在Windows Phone 8的(0.1)的Silverlight应用程序,我可以用这个code:

does anyone know how to access the avaible free space in a universal Windows Phone 8.1 App? In a Windows Phone 8(.1) Silverlight App I could use this Code:

int availableStorage = IsolatedStorageFile.GetUserStoreForApplication().AvailableFreeSpace;

但System.IO.IsolatedStorage不可用在Windows(手机)8.1应用程序。

But System.IO.IsolatedStorage isn't available in a Windows (Phone) 8.1 App.

任何帮助是AP preciated。

Any help is appreciated.

推荐答案

这可能是就像在做解答这个问题。正如我已经试过,像下面的code中的方法返回的自由字节数:

It may be done like in answers to this question. As I've tried, the method like in the code below returns the number of free bytes:

public async Task<UInt64> GetFreeSpace()
{
    StorageFolder local = ApplicationData.Current.LocalFolder;
    var retrivedProperties = await local.Properties.RetrievePropertiesAsync(new string[] { "System.FreeSpace" });
    return (UInt64)retrivedProperties["System.FreeSpace"];
}

// usage:
UInt64 myFreeSpace = await GetFreeSpace();

更多关于调性质以检索(及其格式等),你可以的找到MSDN

一些详细信息 - 请注意,方法得到它的reffering到一个文件夹的可用空间。因此,如果我们运行它是这样的:

Some more information - note that method gets free space of a folder it's reffering to. So if we run it like this:

public async Task<UInt64> GetFreeSpace(StorageFolder folder)
{
    var retrivedProperties = await folder.Properties.RetrievePropertiesAsync(new string[] { "System.FreeSpace" });
    return (UInt64)retrivedProperties["System.FreeSpace"];
}

// and use it like this:
UInt64 spaceOfInstallationFolder = await GetFreeSpace(ApplicationData.Current.LocalFolder);
UInt64 spaceOfMusicLibrary = await GetFreeSpace(KnownFolders.MusicLibrary);

我们会得到用户的电话的设置相关的结果:

We will get results dependant on Settings of the User's Phone:


  • ApplicationData.Current.LocalFolder reffers为安装在App的地方 - 所以,如果用户已经设置应用程序将在SD安装位置,然后你会看到自由的地方在SD卡,

  • KnownFolders.MusicLibrary (例如,它可以是PicturesLibrary等,还要确保你在你的清单文件添加cappabilities,否则你会得到一个异常) - 同样的情况dependand用户设置 - 它可以在手机或SD
  • 空间
  • ApplicationData.Current.LocalFolder reffers to a place where the App was installed - so if User had set that Apps will be installed on SD, then you will see free place on SD card,
  • KnownFolders.MusicLibrary (for example, it can be PicturesLibrary and so on, also ensure that you added cappabilities in your manifest file, otherwise you will get an exception) - the same situation dependand on User settings - it can be space on Phone or SD

所以,如果安装在手机在App,然后reffering到 LocalFolder 你会得到电话的空间。如果你想,那么你可以例如运行方法,这样对SD空间(记得能力):

So if the App is installed on Phone, then reffering to LocalFolder you will get space on Phone. If you want space on SD then you can for example run method like this (remember about capabilities):

UInt64 spaceOfMusicLibrary = await GetFreeSpace((await KnownFolders.RemovableDevices.GetFoldersAsync()).FirstOrDefault());

要在SD(应用程序,音乐,图片)安装

请注意还的情况下用户电话的那获得自由的空间已经设置好一切也没用,因为你将不能够使用它(未经授权的访问)。简单 - 如果你有一个文件夹的访问,你可以得到它的可用空间

Note also that getting free space of the Phone in case User had set everything to be installed on SD (Apps, Music, Pictures) is useless as you won't be able to use it (unauthorized access). Simply - if you have an access to a folder you can get its available space.

这篇关于我怎样才能找出一个通用的Windows Phone 8.1应用程序的avaible自由空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆