2014-07-26 45 views
0

如何使用Xamarin for Android將文件上傳到OneDrive(SkyDrive)?用Xamarin和C將文件從Android應用程序上傳到Microsoft OneDrive#

我對Downloading and uploading files on OneDrive (Android)

信息我可以在Xamarin Studio中使用Microsoft.Live? 我用它在Visual Studio中的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應用程序文件到另一臺服務器? P.S.我無法使用Visual Studio創建Android應用程序,只能使用Xamarin Studio。

回答

0

您可以通過創建和引用Xamarin綁定庫來使用OneDrive for Android。它允許您創建一個綁定項目,該項目使用基於聲明方法的C#包裝程序自動包裝.jar庫。

下面是官方manual

這裏是一個link to Xamarin forums與現有綁定庫項目和示例

相關問題