Android上Xamarin Forms的Application.Current.Properties的存盤位置在哪里?
uj5u.com熱心網友回復:
Application.Current.PropertiesAndroid 上的 Xamarin Forms 存盤位置為:
/data/data/YOUR_PACKAGE_NAME/files/.config/.isolated-storage/PropertyStore.forms
測驗
在 Xamarin 中堅持一些屬性:
Application.Current.Properties["someKey"] = "someValue";
然后:
adb root
adb shell
cd /data/data/YOUR_PACKAGE_NAME/files/.config/.isolated-storage/
ls
演示:

uj5u.com熱心網友回復:
可以直接查看github上的原始碼,試著弄清楚存盤位置在哪里。
搜索檔案Application,并在類里面搜索關鍵字Properties 。
public IDictionary<string, object> Properties
{
get
{
if (_propertiesTask == null)
{
_propertiesTask = GetPropertiesAsync();
}
return _propertiesTask.Result;
}
}
async Task<IDictionary<string, object>> GetPropertiesAsync()
{
var deserializer = DependencyService.Get<IDeserializer>();
if (deserializer == null)
{
Log.Warning("Startup", "No IDeserialzier was found registered");
return new Dictionary<string, object>(4);
}
IDictionary<string, object> properties = await deserializer.DeserializePropertiesAsync().ConfigureAwait(false);
if (properties == null)
properties = new Dictionary<string, object>(4);
return properties;
}
在 Android 平臺上搜索檔案IDeserializer及其實作。
using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
{
if (!store.FileExists(PropertyStoreFile))
return null;
using (IsolatedStorageFileStream stream = store.OpenFile(PropertyStoreFile, System.IO.FileMode.Open, System.IO.FileAccess.Read))
在 Android 平臺上搜索檔案IsolatedStorageFile及其實作。
public class _IsolatedStorageFile : IIsolatedStorageFile
{
readonly IsolatedStorageFile _isolatedStorageFile;
public _IsolatedStorageFile(IsolatedStorageFile isolatedStorageFile)
{
_isolatedStorageFile = isolatedStorageFile;
}
public Task CreateDirectoryAsync(string path)
{
_isolatedStorageFile.CreateDirectory(path);
return Task.FromResult(true);
}
最后,for的實作CreateDirectory是隱藏的,所以我們無法獲得確切的檔案路徑,但是我只是向您展示如何從源代碼中獲取一些東西。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/465924.html
