Application.Current.Properties 位于 Android 的什么位置?
Where is the Application.Current.Properties located on Android?
Xamarin Forms Application.Current.Properties在Android上的存储位置在哪里?
你可以直接查看github上的source code并尝试找出存储位置。
搜索文件 Application
,并在 class 内搜索关键字 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;
}
搜索文件 IDeserializer
及其在 Android 平台上的实现。
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))
搜索文件 IsolatedStorageFile
及其在 Android 平台上的实现。
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);
}
最后,CreateDirectory
的实现被隐藏了,因此我们无法获得确切的文件路径,但我只是向您展示了如何从源代码中获得一些东西。
Application.Current.Properties
在Android上的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
演示:
Xamarin Forms Application.Current.Properties在Android上的存储位置在哪里?
你可以直接查看github上的source code并尝试找出存储位置。
搜索文件 Application
,并在 class 内搜索关键字 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;
}
搜索文件 IDeserializer
及其在 Android 平台上的实现。
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))
搜索文件 IsolatedStorageFile
及其在 Android 平台上的实现。
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);
}
最后,CreateDirectory
的实现被隐藏了,因此我们无法获得确切的文件路径,但我只是向您展示了如何从源代码中获得一些东西。
Application.Current.Properties
在Android上的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
演示: