Google Drive Android API wie zum hochladen einer audio-Datei auf meinem Laufwerk ? , Wie sync-drive-Dateien?

Ich bin in der Demo ist aber ich habe versucht, Sie mit dem Schnellstart-Beispiel, in dem ein Bild hochgeladen wurde. aber ich bin nicht immer wie zum hochladen einer audio-Datei, in der ich geben den Pfad zu meinen Dateien oder Vorsatz Picker, um die Datei auszuwählen.Ich bin mit createFile() Methode

  1. wie zum hochladen einer audio-Datei auf meinem Laufwerk?

    • Ich brauche, um zu konvertieren, um alle streams ?
      • warum google diese so sehr kompliziert, nur um Datei hochladen?
  2. Wie Synch-Laufwerk Dateien ?

  3. Wie streamen (Abspielen von audio-Datei von Festplatte)?

Den code Unten laden Sie einfach die Datei, die nichts enthält.

public class MainActivity extends Activity implements ConnectionCallbacks,
    OnConnectionFailedListener {

private static final String TAG = "android-drive-quickstart";
//private static final int REQUEST_CODE_CAPTURE_IMAGE = 1;
private static final int REQUEST_CODE_CREATOR = 2;
private static final int REQUEST_CODE_RESOLUTION = 3;
private static final int PICKFILE_RESULT_CODE = 1;
private static Uri fileUri;
private ContentsResult result;
private GoogleApiClient mGoogleApiClient;
private Bitmap mBitmapToSave;


@Override
protected void onResume() {
    super.onResume();
    if (mGoogleApiClient == null) {
        //Create the API client and bind it to an instance variable.
        //We use this instance as the callback for connection and connection
        //failures.
        //Since no account name is passed, the user is prompted to choose.
        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addApi(Drive.API)
                .addScope(Drive.SCOPE_FILE)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .build();
    }
    //Connect the client. Once connected, the camera is launched.
    mGoogleApiClient.connect();
}




@Override
public void onConnectionFailed(ConnectionResult result) {
    //Called whenever the API client fails to connect.
    Log.i(TAG, "GoogleApiClient connection failed: " + result.toString());
    if (!result.hasResolution()) {
        //show the localized error dialog.
        showToast("Error in on connection failed");
        GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(), this, 0).show();
        return;
    }
    //The failure has a resolution. Resolve it.
    //Called typically when the app is not yet authorized, and an
    //authorization
    //dialog is displayed to the user.
    try {
        result.startResolutionForResult(this, REQUEST_CODE_RESOLUTION);
    } catch (SendIntentException e) {
        showToast("error"+e.toString());
        Log.e(TAG, "Exception while starting resolution activity", e);
    }
}


@Override
public void onConnected(Bundle connectionHint) {
    Log.i(TAG, "API client connected.");

    showToast("Inside Connected");
    result = Drive.DriveApi.newContents(mGoogleApiClient).await();

    showToast(""+result.getContents().toString());
    OutputStream outputStream = result.getContents().getOutputStream();
    ByteArrayOutputStream bitmapStream = new ByteArrayOutputStream();
    //java.io.File fileContent = new java.io.File(fileUri.getPath());


    MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
    .setTitle("New file")
    .setMimeType("audio/MP3")
    .setStarred(true).build();
    showToast("meta data created");
    DriveFileResult dfres= Drive.DriveApi.getRootFolder(getGoogleApiClient())
    .createFile(getGoogleApiClient(), changeSet, result.getContents())
    .await();
    showToast("await() complete");
    if (!result.getStatus().isSuccess()) {
        showToast("Error while trying to create the file");
        return;
    }
    showToast("Created a file: " + dfres.getDriveFile().getDriveId());
}



private void saveFileToDrive()
{

}


@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    if (requestCode == REQUEST_CODE_RESOLUTION && resultCode == RESULT_OK) {
        mGoogleApiClient.connect();
        showToast("Connected");
    }
}



@Override
protected void onPause() {
    if (mGoogleApiClient != null) {
        mGoogleApiClient.disconnect();
    }
    super.onPause();
}


public void showToast(final String toast) {
    runOnUiThread(new Runnable() {
      @Override
      public void run() {
        Toast.makeText(getApplicationContext(), toast, Toast.LENGTH_SHORT).show();
      }
    });
  }

public GoogleApiClient getGoogleApiClient() {
    return mGoogleApiClient;
  }

@Override
public void onConnectionSuspended(int cause) {
    Log.i(TAG, "GoogleApiClient connection suspended");
}

}

Schreibe einen Kommentar