使用Xamarin和c#从Android应用程序上传文件到Microsoft OneDrive
本文关键字:程序上 文件 OneDrive Microsoft 应用程序 应用 Xamarin Android 使用 | 更新日期: 2023-09-27 18:15:14
如何将文件上传到OneDrive (SkyDrive)与Xamarin for Android?
我有关于OneDrive (Android)下载和上传文件的信息
我可以用微软吗?住在Xamarin Studio?我在Visual Studio for Windows Phone应用程序中使用它:
c#: private void skydrive_SessionChanged(object sender, LiveConnectSessionChangedEventArgs e)
{
if (e != null && e.Status == LiveConnectSessionStatus.Connected)
{
this.client = new LiveConnectClient(e.Session);
this.GetAccountInformations();
}
else
{
this.client = null;
InfoText.Text = e.Error != null ? e.Error.ToString() : string.Empty;
}
}
private async void GetAccountInformations()
{
try
{
LiveOperationResult operationResult = await this.client.GetAsync("me");
var jsonResult = operationResult.Result as dynamic;
string firstName = jsonResult.first_name ?? string.Empty;
string lastName = jsonResult.last_name ?? string.Empty;
InfoText.Text = "Welcome " + firstName + " " + lastName;
}
catch (Exception e)
{
InfoText.Text = e.ToString();
}
}
private async void btnUpload_Click(object sender, RoutedEventArgs e)
{
using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
{
using (var fileStream = store.OpenFile(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
{
try
{
LiveOperationResult res = await client.BackgroundUploadAsync("me/skydrive",
new Uri("/shared/transfers/" + fileName, UriKind.Relative),
OverwriteOption.Overwrite
);
InfoText.Text = "File " + fileName + " uploaded";
}
catch (Exception ex)
{
}
}
}
}
XAML: <Controls:SignInButton Canvas.Left="10" Canvas.Top="351" Content="Button"
Name="skydrive" Scopes="wl.basic wl.signin wl.offline_access wl.skydrive_update"
SessionChanged="skydrive_SessionChanged"
ClientId="00000000########"/>
<TextBlock Name="InfoText" Width="167" Height="42" Canvas.Left="192" Canvas.Top="367"></TextBlock>
<Button Name="btnUpload" Canvas.Left="10" Canvas.Top="430" Width="166" Click="btnUpload_Click">Upload</Button>
是否有其他方法将文件从Android应用程序上传到其他服务器?注:我不能使用Visual Studio创建Android应用程序,只能使用Xamarin Studio。
您可以通过创建和引用Xamarin绑定库来使用OneDrive for Android。它允许您创建一个绑定项目,该项目可以基于声明性方法自动使用c#包装器包装.jar库。
官方手册
这里是Xamarin论坛的链接,有现有的绑定库项目和示例