无法在Google云端硬盘中创建电子表格

时间:2015-02-04 14:39:01

标签: google-drive-api google-sheets google-spreadsheet-api google-drive-android-api

我尝试在Android中创建电子表格。它发送了一条成功消息,但它没有被创建。

我使用以下代码创建它:

MetadataChangeSet metadataChangeSet = new MetadataChangeSet.Builder()
.setMimeType("application/vnd.google-apps.spreadsheet").setTitle("MonthExpense").build();
IntentSender intentSender = Drive.DriveApi
.newCreateFileActivityBuilder()
.setInitialMetadata(metadataChangeSet)
.setInitialDriveContents(result.getDriveContents())
.build(appobject.mGoogleApiClient);
try {
activity.startIntentSenderForResult(intentSender, 56, null, 0, 0, 0);
}

如果我使用任何其他mimetype它可以正常工作,任何人都可以以正确的方式指导我。

修改 如果我尝试任何其他mime类型,它可以解决问题,所以我猜这个问题与" application / vnd.google-apps.spreadsheet"

相关

1 个答案:

答案 0 :(得分:0)

尝试将application / vnd.google-apps.spreadsheet更改为application / vnd.ms-excel

创建一个WorkBook。这是我工作代码的结尾

final private ResultCallback<DriveContentsResult> driveContentsCallback = new ResultCallback<DriveContentsResult>() {
    @Override
    public void onResult(final DriveContentsResult result) {
        if (!result.getStatus().isSuccess()) {
            showMessage("Error while trying to create new file contents");
            return;
        }
        final DriveContents driveContents = result.getDriveContents();

        // Perform I/O off the UI thread.
        new Thread() {
            @Override
            public void run() {

 //CREATE YOUR WORKBOOK HERE
ByteArrayOutputStream bos = new ByteArrayOutputStream();
                    try {
                        wb.write(bos);
                        byte[] bytes = bos.toByteArray();
                        outputStream.write(bytes);
                        //WORKBOOK FILENAME
                        writer.write(fileName);
                        wb.close();
                    } catch (IOException e) {
                        Log.e(TAG, e.getMessage());
                    }

                    MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
                            .setTitle(fileName)
                            .setMimeType("application/vnd.ms-excel")
                            .setStarred(true).build();

                    // create a file on root folder
                    Drive.DriveApi
                            .getRootFolder(getGoogleApiClient())
                            .createFile(getGoogleApiClient(), changeSet,
                                    driveContents)
                            .setResultCallback(fileCallback);