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


Java DriveApi.DriveContentsResult方法代码示例

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


在下文中一共展示了DriveApi.DriveContentsResult方法的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: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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:rbtr,项目名称:Drive-Database-Sync,代码行数:30,代码来源:DriveSyncController.java

示例10: DownloadFile

import com.google.android.gms.drive.DriveApi; //导入方法依赖的package包/类
public void DownloadFile(DriveId driveId, final OnFileDownloaded callback) {
    activeOperations = true;
    PendingResult<DriveApi.DriveContentsResult> contentsResult = driveId.asDriveFile().open(getApiClient(), DriveFile.MODE_READ_ONLY, null);
    contentsResult.setResultCallback(new ResultCallback<DriveApi.DriveContentsResult>() {
        @Override
        public void onResult(DriveApi.DriveContentsResult driveContentsResult) {
            Log.d("DocumentList", "In file open");
            if (driveContentsResult.getDriveContents() == null) {
                //There is no file
                callback.onFileDownloaded(null);
                activeOperations = false;
                return;
            }
            callback.onFileDownloaded(Utils.readFromInputStream(driveContentsResult.getDriveContents().getInputStream()));
            activeOperations = false;
        }
    });
}
 
开发者ID:rkkr,项目名称:drive-notepad,代码行数:19,代码来源:DriveService.java

示例11: onResult

import com.google.android.gms.drive.DriveApi; //导入方法依赖的package包/类
@Override
public void onResult(DriveApi.DriveContentsResult result) {
    MetadataChangeSet metadataChangeSet = new MetadataChangeSet.Builder()
            .setTitle("cumulustv_channels.json")
            .setDescription("JSON list of channels that can be imported using CumulusTV to view live streams")
            .setMimeType("application/json").build();
    IntentSender intentSender = Drive.DriveApi
            .newCreateFileActivityBuilder()
            .setActivityTitle("cumulustv_channels.json")
            .setInitialMetadata(metadataChangeSet)
            .setInitialDriveContents(result.getDriveContents())
            .build(CloudStorageProvider.getInstance().getClient());
    try {
        mActivity.startIntentSenderForResult(
                intentSender, REQUEST_CODE_CREATOR, null, 0, 0, 0);
    } catch (IntentSender.SendIntentException e) {
        Log.w(TAG, "Unable to send intent", e);
    }
}
 
开发者ID:Fleker,项目名称:CumulusTV,代码行数:20,代码来源:LeanbackFragment.java

示例12: createDriveData

import com.google.android.gms.drive.DriveApi; //导入方法依赖的package包/类
public static void createDriveData(Activity activity, GoogleApiClient gapi,
        final ResultCallback<DriveApi.DriveContentsResult> driveContentsCallback) {
    PermissionUtils.requestPermissionIfDisabled(activity,
            android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
            activity.getString(R.string.permission_storage_rationale));
    if(gapi == null)
        gapi = mCloudStorageProvider.connect(activity);
    try {
        final GoogleApiClient finalGapi = gapi;
        new AlertDialog.Builder(activity)
                .setTitle(R.string.create_sync_file_title)
                .setMessage(R.string.create_sync_file_description)
                .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Drive.DriveApi.newDriveContents(finalGapi)
                                .setResultCallback(driveContentsCallback);
                    }
                })
                .setNegativeButton(R.string.no, null)
                .show();
    } catch(Exception ignored) {
        Toast.makeText(activity, "Error creating drive data: " + ignored.getMessage(),
                Toast.LENGTH_SHORT).show();
    }
}
 
开发者ID:Fleker,项目名称:CumulusTV,代码行数:27,代码来源:ActivityUtils.java

示例13: onResult

import com.google.android.gms.drive.DriveApi; //导入方法依赖的package包/类
@Override
public void onResult(DriveApi.DriveContentsResult result) {
    MetadataChangeSet metadataChangeSet = new MetadataChangeSet.Builder()
            .setTitle("cumulustv_channels.json")
            .setDescription("JSON list of channels that can be imported using " +
                    "CumulusTV to view live streams")
            .setMimeType("application/json").build();
    IntentSender intentSender = Drive.DriveApi
            .newCreateFileActivityBuilder()
            .setActivityTitle("cumulustv_channels.json")
            .setInitialMetadata(metadataChangeSet)
            .setInitialDriveContents(result.getDriveContents())
            .build(CloudStorageProvider.getInstance().getClient());
    try {
        startIntentSenderForResult(
                intentSender, REQUEST_CODE_CREATOR, null, 0, 0, 0);
    } catch (IntentSender.SendIntentException e) {
        Log.w(TAG, "Unable to send intent", e);
    }
}
 
开发者ID:Fleker,项目名称:CumulusTV,代码行数:21,代码来源:MainActivity.java

示例14: onResult

import com.google.android.gms.drive.DriveApi; //导入方法依赖的package包/类
@Override
public void onResult(@NonNull DriveApi.DriveContentsResult result) {
    if(result.getStatus().isSuccess()) {
        try {
            FileDescriptor file = result.getDriveContents()
                    .getParcelFileDescriptor().getFileDescriptor();
            FileInputStream fis = new FileInputStream(file);
            mData = new byte[fis.available()];
            int nbr = fis.read(mData);
            fis.close();
            if(nbr < mData.length) {
                mListener.onSyncFailed(CA.DATA_RECEIVED);
                return;
            }
            mListener.onSyncProgress(CA.DATA_RECEIVED);
        }catch(IOException e) {
            mListener.onSyncFailed(CA.DATA_RECEIVED);
            Log.w(LOG_TAG, "Reading contents received IOException");
        }
    }
    else {
        mListener.onSyncFailed(CA.NO_DATA);
        Log.w(LOG_TAG, "Retrieving contents received error");
    }
}
 
开发者ID:zhuqianqian,项目名称:Passbook,代码行数:26,代码来源:DriveSyncService.java

示例15: onNewContents

import com.google.android.gms.drive.DriveApi; //导入方法依赖的package包/类
public void onNewContents(DriveApi.DriveContentsResult result)
{
    if (!result.getStatus().isSuccess())
    {
        Toast.makeText(App.getAppContext(), "Error while trying to create new file contents", Toast.LENGTH_SHORT).show();
        return;
    }

    MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
            .setTitle("Finanvita " + DateUtils.formatDateTime(App.getAppContext(), System.currentTimeMillis(), DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_YEAR))
            .setMimeType("application/json")
            .setStarred(false).build();

    Drive.DriveApi.getRootFolder(client).createFile(client, changeSet, result.getDriveContents()).setResultCallback(new ResultCallback<DriveFolder.DriveFileResult>() {
        @Override
        public void onResult(DriveFolder.DriveFileResult driveFileResult) {
            onCreateFile(driveFileResult);
        }
    });
}
 
开发者ID:kimkha,项目名称:Finanvita,代码行数:21,代码来源:YourDataActivity.java


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