Google Drive API implementation Xamarin Android

后端 未结 1 1831
Happy的楠姐
Happy的楠姐 2020-12-16 08:42

Our application should have the functionality to save Application files to Google Drive. Of course, using the local configured account.

From Android API i tried to

1条回答
  •  孤街浪徒
    2020-12-16 09:14

    The basic steps (see the link below for full details):

    • Create GoogleApiClient with the Drive API and Scope

    • Try to connect (login) the GoogleApiClient

    • The first time you try to connect it will fail as the user has not selected a Google Account that should be used

      • Use StartResolutionForResult to handle this condition
    • When GoogleApiClient is connected

      • Request a Drive content (DriveContentsResult) to write the file contents to.

      • When the result is obtained, write data into the Drive content.

      • Set the metadata for the file

      • Create the Drive-based file with the Drive content

    Note: This example assumes that you have Google Drive installed on your device/emulator and you have registered your app in Google's Developer API Console with the Google Drive API Enabled.

    C# Example:

    [Activity(Label = "DriveOpen", MainLauncher = true, Icon = "@mipmap/icon")]
    public class MainActivity : Activity, GoogleApiClient.IConnectionCallbacks, IResultCallback, IDriveApiDriveContentsResult
    {
        const string TAG = "GDriveExample";
        const int REQUEST_CODE_RESOLUTION = 3;
    
        GoogleApiClient _googleApiClient;
    
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
    
            SetContentView(Resource.Layout.Main);
    
            Button button = FindViewById

    Ref: https://developers.google.com/drive/android/create-file

    0 讨论(0)
提交回复
热议问题