当前位置: 首页>>代码示例>>Java>>正文


Java DriveApi类代码示例

本文整理汇总了Java中com.google.android.gms.drive.DriveApi的典型用法代码示例。如果您正苦于以下问题:Java DriveApi类的具体用法?Java DriveApi怎么用?Java DriveApi使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DriveApi类属于com.google.android.gms.drive包,在下文中一共展示了DriveApi类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: saveDriveFile

import com.google.android.gms.drive.DriveApi; //导入依赖的package包/类
/**
 * Save the {@code DriveFile} with the specific driveId.
 *
 * @param id {@link DriveId} of the file.
 * @param content The content to be saved in the {@code DriveFile}.
 * @return Return value indicates whether the save was successful.
 */
public boolean saveDriveFile(DriveId id, String content) throws IOException {
    DriveFile theFile = Drive.DriveApi.getFile(mGoogleApiClient, id);
    DriveApi.DriveContentsResult result =
            theFile.open(mGoogleApiClient, DriveFile.MODE_WRITE_ONLY, null).await();

    try {
        IOUtils.writeToStream(content, result.getDriveContents().getOutputStream());
        // Update the last viewed.
        MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
                .setLastViewedByMeDate(new Date())
                .build();
        return result.getDriveContents().commit(mGoogleApiClient, changeSet)
                .await().isSuccess();
    } catch (IOException io) {
        result.getDriveContents().discard(mGoogleApiClient);
        throw io;
    }
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:26,代码来源:DriveHelper.java

示例2: onResult

import com.google.android.gms.drive.DriveApi; //导入依赖的package包/类
@Override
public void onResult(@NonNull DriveApi.DriveContentsResult driveContentsResult) {
    try {
        InputStream inputStream = driveContentsResult.getDriveContents().getInputStream();
        byte[] b = new byte[4096];
        String current = "";
        int read = 0;

        while ((read = inputStream.read(b, 0, 4096)) != -1)
            current += new String(b, 0, read);

        if (current.length() > 0)
            DataManager.saveJsonAsData(new JSONObject(current));
        driveContentsResult.getDriveContents().reopenForWrite(mGoogleApiClient).setResultCallback(writeDriveCallback);
    } catch (IOException | JSONException e) {
        Toast.makeText(getApplicationContext(), getString(R.string.drive_fail_get_data), Toast.LENGTH_LONG).show();
    }
}
 
开发者ID:JeanBarriere,项目名称:Note,代码行数:19,代码来源:MainActivity.java

示例3: FindOrCreateDriveFile

import com.google.android.gms.drive.DriveApi; //导入依赖的package包/类
void FindOrCreateDriveFile(){
    // Check if we already have a driveID file
    Context context = getApplicationContext();
    SharedPreferences mSharedPreferences = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_PRIVATE);
    sPreviousDriveID = mSharedPreferences.getString(PREF_DRIVE_ID,"");
    if (sPreviousDriveID.length() > 0){
        Log.v(TAG, "Using saved drive ID: " + sPreviousDriveID);
        Drive.DriveApi.fetchDriveId(getGoogleApiClient(),sPreviousDriveID)
                .setResultCallback(driveFetchIDCallback);
    } else {
        // create new contents resource
        Log.v(TAG, "Attempting to create new drive file");
        Drive.DriveApi.newDriveContents(getGoogleApiClient())
                .setResultCallback(driveContentsCallback);
    }
}
 
开发者ID:etsy,项目名称:divertsy-client,代码行数:17,代码来源:SyncToDriveService.java

示例4: getContentsFromDrive

import com.google.android.gms.drive.DriveApi; //导入依赖的package包/类
public String getContentsFromDrive(DriveId id) throws IOException {
    DriveFile theFile = Drive.DriveApi.getFile(mGoogleApiClient, id);
    DriveApi.DriveContentsResult result =
            theFile.open(mGoogleApiClient, DriveFile.MODE_READ_ONLY, null).await();
    DriveContents driveContents = result.getDriveContents();
    try {
        if (driveContents != null) {
            return IOUtils.readAsString(driveContents.getInputStream());
        }
    } finally {
        if (driveContents != null) {
            driveContents.discard(mGoogleApiClient);
        }
    }
    return null;
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:17,代码来源:DriveHelper.java

示例5: createEmptyDriveFile

import com.google.android.gms.drive.DriveApi; //导入依赖的package包/类
/**
 * Create an empty file with the given {@code fileName} and {@code mimeType}.
 *
 * @return {@link DriveId} of the specific file.
 */
private DriveId createEmptyDriveFile(String fileName, String mimeType) {
    DriveApi.DriveContentsResult result =
            Drive.DriveApi.newDriveContents(mGoogleApiClient).await();

    MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
            .setTitle(fileName)
            .setMimeType(mimeType)
            .setStarred(true)
            .build();

    // Create a new file with the given changeSet in the AppData folder.
    DriveFolder.DriveFileResult driveFileResult = Drive.DriveApi.getAppFolder(mGoogleApiClient)
            .createFile(mGoogleApiClient, changeSet, result.getDriveContents())
            .await();
    return driveFileResult.getDriveFile().getDriveId();
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:22,代码来源:DriveHelper.java

示例6: commitToNewFile

import com.google.android.gms.drive.DriveApi; //导入依赖的package包/类
/**
 * Creates a new file and adds the {@link DriveContents} passed to this method.
 * @return Returns a boolean stating the success of this operation
 */
private boolean commitToNewFile(DriveContents driveContents) {
    DebugLog.logMethod();
    MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
            .setTitle("CouponsTrackerData.txt")
            .setMimeType("text/plain")
            .build();

    DriveFolder.DriveFileResult driveFileResult = Drive.DriveApi
            .getAppFolder(getGoogleApiClient())
            .createFile(getGoogleApiClient(), changeSet, driveContents)
            .await();
    DebugLog.logMessage("DriveFileResult: statusCode - " + driveFileResult.getStatus().getStatusCode()
            + ", statusMessage: " + driveFileResult.getStatus().getStatusMessage());
    return driveFileResult.getStatus().isSuccess();
}
 
开发者ID:darsh2,项目名称:CouponsTracker,代码行数:20,代码来源:ExportToDriveService.java

示例7: getDriveFile

import com.google.android.gms.drive.DriveApi; //导入依赖的package包/类
/**
 * Returns the app specific {@link DriveFile} if it has already been created. Else
 * returns null.
 */
protected final DriveFile getDriveFile() {
    DebugLog.logMethod();

    DriveApi.MetadataBufferResult metadataBufferResult = Drive.DriveApi.getAppFolder(getGoogleApiClient())
            .listChildren(getGoogleApiClient())
            .await();
    DebugLog.logMessage("Status code: " + metadataBufferResult.getStatus().getStatusCode()
            + "\nStatus message: " + metadataBufferResult.getStatus().getStatusMessage());
    if (!metadataBufferResult.getStatus().isSuccess()) {
        metadataBufferResult.release();
        DebugLog.logMessage("MetadataBufferResult failure");
        return null;
    }

    MetadataBuffer metadataBuffer = metadataBufferResult.getMetadataBuffer();
    DebugLog.logMessage("MetadataBuffer count: " + metadataBuffer.getCount());
    if (metadataBuffer.getCount() == 0) {
        metadataBuffer.release();
        return null;
    }
    DriveId driveId = metadataBuffer.get(0).getDriveId();
    metadataBuffer.release();
    metadataBufferResult.release();
    return driveId.asDriveFile();
}
 
开发者ID:darsh2,项目名称:CouponsTracker,代码行数:30,代码来源:GoogleDriveService.java

示例8: doInBackgroundConnected

import com.google.android.gms.drive.DriveApi; //导入依赖的package包/类
@Override
protected Boolean doInBackgroundConnected(EditContentParams... args) {
    DriveFile file = args[0].getFileToWrite();
    String dataToWrite = args[0].getDataToWrite();

    try {
        DriveApi.DriveContentsResult driveContentsResult = file.open(
                getGoogleApiClient(), DriveFile.MODE_WRITE_ONLY, null).await();
        if (!driveContentsResult.getStatus().isSuccess()) {
            return false;
        }
        DriveContents driveContents = driveContentsResult.getDriveContents();
        OutputStream outputStream = driveContents.getOutputStream();
        outputStream.write(dataToWrite.getBytes());
        com.google.android.gms.common.api.Status status =
                driveContents.commit(getGoogleApiClient(), null).await();
        return status.getStatus().isSuccess();
    } catch (IOException e) {
        AppUtils.showMessage(context,"Failed to write data to file.");
    }
    return false;
}
 
开发者ID:robertsimoes,项目名称:Flow,代码行数:23,代码来源:EditContentsAsyncTask.java

示例9: queryFile

import com.google.android.gms.drive.DriveApi; //导入依赖的package包/类
private void queryFile() {
    Query query = new Query.Builder()
            .addFilter(Filters.contains(SearchableField.TITLE, "Note.json"))
            .build();
    Drive.DriveApi.query(
            mGoogleApiClient, query).setResultCallback(result -> {
        if (!result.getStatus().isSuccess()) {
            if (BuildConfig.DEBUG)
                Log.d(TAG, "Problem while retrieving results");
            return;
        }

        Metadata metadata = result.getMetadataBuffer().get(0);
        if (BuildConfig.DEBUG)
            Log.d(TAG, "metadata.getDriveId():" + metadata.getDriveId());
        readFileFromDrive(metadata.getDriveId());
    });
}
 
开发者ID:Art2Cat,项目名称:MoonlightNote,代码行数:19,代码来源:SettingsActivity.java

示例10: doInBackgroundConnected

import com.google.android.gms.drive.DriveApi; //导入依赖的package包/类
@Override
protected String doInBackgroundConnected(DriveId... params) {
    String contents = null;
    DriveFile file = params[0].asDriveFile();
    DriveApi.DriveContentsResult driveContentsResult =
            file.open(getGoogleApiClient(), DriveFile.MODE_READ_ONLY, null).await();
    if (!driveContentsResult.getStatus().isSuccess()) {
        return null;
    }
    DriveContents driveContents = driveContentsResult.getDriveContents();
    BufferedReader reader = new BufferedReader(
            new InputStreamReader(driveContents.getInputStream()));
    StringBuilder builder = new StringBuilder();
    String line;
    try {
        while ((line = reader.readLine()) != null) {
            builder.append(line);
        }
        contents = builder.toString();
    } catch (IOException e) {
        Log.e(TAG, "IOException while reading from the stream", e);
    }

    driveContents.discard(getGoogleApiClient());
    return contents;
}
 
开发者ID:webianks,项目名称:HatkeMessenger,代码行数:27,代码来源:RetrieveDriveFileContentsAsyncTask.java

示例11: doInBackgroundConnected

import com.google.android.gms.drive.DriveApi; //导入依赖的package包/类
@Override
protected Boolean doInBackgroundConnected(DriveFile... args) {
    DriveFile file = args[0];
    try {
        DriveApi.DriveContentsResult driveContentsResult = file.open(
                getGoogleApiClient(), DriveFile.MODE_WRITE_ONLY, null).await();
        if (!driveContentsResult.getStatus().isSuccess()) {
            return false;
        }
        DriveContents driveContents = driveContentsResult.getDriveContents();
        OutputStream outputStream = driveContents.getOutputStream();
        outputStream.write(Helpers.getSMSJson(context).getBytes());
        com.google.android.gms.common.api.Status status =
                driveContents.commit(getGoogleApiClient(), null).await();
        return status.getStatus().isSuccess();
    } catch (IOException e) {
        Log.e(TAG, "IOException while appending to the output stream", e);
    }
    return false;
}
 
开发者ID:webianks,项目名称:HatkeMessenger,代码行数:21,代码来源:EditContentsAsyncTask.java

示例12: doAfterConnectedStuff

import com.google.android.gms.drive.DriveApi; //导入依赖的package包/类
private void doAfterConnectedStuff() {

        if (progressDialog == null)
            progressDialog = new ProgressDialog(this);

        if (type == Constants.TYPE_BACKUP)
            progressDialog.setTitle(getString(R.string.google_drive_backup));
        else
            progressDialog.setTitle(getString(R.string.google_drive_restore));

        progressDialog.setMessage(getString(R.string.please_wait));
        progressDialog.setIndeterminate(true);
        progressDialog.show();

        Drive.DriveApi.newDriveContents(getGoogleApiClient()).setResultCallback(driveContentsCallback);

    }
 
开发者ID:webianks,项目名称:HatkeMessenger,代码行数:18,代码来源:SettingsActivity.java

示例13: onConnected

import com.google.android.gms.drive.DriveApi; //导入依赖的package包/类
@Override
public void onConnected(Bundle connectionHint) {
    Log.i(TAG, "API client connected.");

    //when the client is connected i have two possibility: backup (bckORrst -> true) or restore (bckORrst -> false)
    if (bckORrst)
        saveFileToDrive();
    else {
        IntentSender intentSender = Drive.DriveApi
                .newOpenFileActivityBuilder()
                .setMimeType(new String[]{"application/db"})
                .build(mGoogleApiClient);
        try {
            startIntentSenderForResult(intentSender, REQUEST_CODE_OPENER, null, 0, 0, 0);
            Log.i(TAG, "Open File Intent send");
        } catch (IntentSender.SendIntentException e) {
            Log.w(TAG, "Unable to send Open File Intent", e);
        }
    }
}
 
开发者ID:prof18,项目名称:Database-Backup-Restore,代码行数:21,代码来源:MainActivity.java

示例14: onResult

import com.google.android.gms.drive.DriveApi; //导入依赖的package包/类
/**
 * Handles the result of the query. If the results are nonzero, passes up the {@link Metadata}
 * out of the result one at a time through {@link QuerierResultCallback#onQuerierResult(Metadata)}
 * with the {@link QuerierResultCallback} registered in ths {@link Querier}. If the results are
 * null, calls {@link QuerierResultCallback#onNoQuerierResult()}
 *
 * @param result the result of the query
 */
@Override
public void onResult(DriveApi.MetadataBufferResult result) {
    if (!result.getStatus().isSuccess()) {
        Log.e("Querier", "Problem while retrieving files");
        return;
    }

    // Get the metadata buffer
    MetadataBuffer buffer = result.getMetadataBuffer();

    // Check for file dne
    if (buffer.getCount() == 0) {
        // Call null result callback
        callback.onNoQuerierResult();
    }

    // Get the metadata
    for (Metadata m : buffer) {
        if (m.isInAppFolder() && !m.isTrashed()) {
            callback.onQuerierResult(m);
            break;
        }
    }
}
 
开发者ID:akilawickey,项目名称:pinPotha,代码行数:33,代码来源:Querier.java

示例15: onFileResultsReady

import com.google.android.gms.drive.DriveApi; //导入依赖的package包/类
/**
 * Handles the DriveContentsResult returned from the request to get the DriveFile of the
 * Database.
 *
 * @param result the DriveContentsResult representing the Drive copy of the Database
 */
@Override
public void onFileResultsReady(DriveApi.DriveContentsResult result) {

    if (!mDriveClient.isConnected()) {
        mDriveClient.connect();
    }

    this.result = result;

    int which = deQueue();

    switch (which) {
        case PUT:
            writeLocalDbToCloudStream(result.getDriveContents().getOutputStream());
            result.getDriveContents().commit(mDriveClient, null);
            break;
        case GET:
            writeCloudStreamToLocalDb(result.getDriveContents().getInputStream());
            break;
    }
    if (ongoingRequest) {
        mDriveLayer.getFile(localDb.getName());
    }
}
 
开发者ID:akilawickey,项目名称:pinPotha,代码行数:31,代码来源:DriveSyncController.java


注:本文中的com.google.android.gms.drive.DriveApi类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。