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


Java DriveContents类代码示例

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


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

示例1: onResult

import com.google.android.gms.drive.DriveContents; //导入依赖的package包/类
@Override
public void onResult(DriveContentsResult result) {
    if (!result.getStatus().isSuccess()) {
        Log.i(TAG, "Error creating new file contents");
        return;
    }
    final DriveContents driveContents = result.getDriveContents();
    new Thread() {
        @Override
        public void run() {
            OutputStream outputStream = driveContents.getOutputStream();
            addTextfileToOutputStream(outputStream);
            MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
                    .setTitle("testFile")
                    .setMimeType("text/plain")
                    .setDescription("This is a text file uploaded from device")
                    .setStarred(true).build();
            Drive.DriveApi.getRootFolder(googleApiClient)
                    .createFile(googleApiClient, changeSet, driveContents)
                    .setResultCallback(fileCallback);
        }
    }.start();
}
 
开发者ID:JonathanImperato,项目名称:Service-Notes,代码行数:24,代码来源:UploadFileActivity.java

示例2: getContentsFromDrive

import com.google.android.gms.drive.DriveContents; //导入依赖的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

示例3: writeToDriveFile

import com.google.android.gms.drive.DriveContents; //导入依赖的package包/类
/**
 * Write the couponsJson to the driveContents, creating or updating the file as required.
 * Returns a boolean indicating success of this task.
 */
private boolean writeToDriveFile(DriveContents driveContents, String couponsJson, boolean isNewFile) {
    DebugLog.logMethod();
    OutputStream outputStream = driveContents.getOutputStream();
    /*
    Ref: http://stackoverflow.com/a/4069104/3946664
    
    Avoiding usage of outputStream.write() since it requires a byte array to be
    passed. In case of String, the getBytes() should be avoided since it uses
    default encoding of the JVM which cannot be reliably predicted in a portable
    manner. Hence using Writer's write method.
     */
    Writer writer = new OutputStreamWriter(outputStream);
    try {
        writer.write(couponsJson);
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
        DebugLog.logMessage(e.getMessage());
        return false;
    }
    return isNewFile ? commitToNewFile(driveContents) : commitToExistingFile(driveContents);
}
 
开发者ID:darsh2,项目名称:CouponsTracker,代码行数:27,代码来源:ExportToDriveService.java

示例4: commitToNewFile

import com.google.android.gms.drive.DriveContents; //导入依赖的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

示例5: doInBackgroundConnected

import com.google.android.gms.drive.DriveContents; //导入依赖的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.DriveContents; //导入依赖的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.DriveContents; //导入依赖的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: createNewFile

import com.google.android.gms.drive.DriveContents; //导入依赖的package包/类
/**
 * Create a new file on Drive.
 *
 * @param title    The name of the file
 * @param hash     The file hash
 * @param contents The file content
 */
private void createNewFile(@NonNull String title, @NonNull String hash,
                           @NonNull DriveContents contents) {
    if(mResourceClient == null || mDriveFolder == null) {
        return;
    }
    final MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
            .setTitle(title)
            .setCustomProperty(sHashKey, hash).build();
    final ExecutionOptions options = new ExecutionOptions.Builder()
            .setNotifyOnCompletion(true).build();
    try {
        Tasks.await(mResourceClient.createFile(mDriveFolder, changeSet, contents, options));
    } catch(ExecutionException | InterruptedException e) {
        Log.w(TAG, "Failed to create remote file", e);
    }
}
 
开发者ID:ultramega,项目名称:flavordex,代码行数:24,代码来源:PhotoSyncHelper.java

示例9: writeFile

import com.google.android.gms.drive.DriveContents; //导入依赖的package包/类
public Observable<Void> writeFile(final DriveId driveId, final InputStream inputStream) {
	return Observable.defer(new Func0<Observable<Void>>() {
		@Override
		public Observable<Void> call() {
			// OutputStream outputStream = Drive.DriveApi.getFile(googleApiClientManager.getGoogleApiClient(), driveId)
			DriveContents driveContents = Drive.DriveApi.getFile(googleApiClientManager.getGoogleApiClient(), driveId)
					.open(googleApiClientManager.getGoogleApiClient(), DriveFile.MODE_WRITE_ONLY, null)
					.await()
					.getDriveContents();

			// copy file to drive contents
			try {
				copyStream(inputStream, driveContents.getOutputStream());
			} catch (IOException e) {
				Timber.e(e, "failed to read image");
				return Observable.error(e);
			}

			// commit changes
			driveContents.commit(googleApiClientManager.getGoogleApiClient(), new MetadataChangeSet.Builder().build()).await();
			return Observable.just(null);
		}
	});
}
 
开发者ID:FauDroids,项目名称:BabyFace,代码行数:25,代码来源:GoogleDriveManager.java

示例10: doInBackgroundConnected

import com.google.android.gms.drive.DriveContents; //导入依赖的package包/类
@Override
protected String doInBackgroundConnected(DriveId... params) {
    String contents = null;
    DriveFile file = Drive.DriveApi.getFile(getGoogleApiClient(), params[0]);
    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) {

    }

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

示例11: updateSums

import com.google.android.gms.drive.DriveContents; //导入依赖的package包/类
/**
 * Updates the App Data file associated with {@code driveContents} with the current sum.
 */
private void updateSums(DriveContents driveContents) {
  writeSums(driveContents);

  mDriveResourceClient.commitContents(driveContents, /* metadataChangeSet= */ null)
      .addOnSuccessListener(new OnSuccessListener<Void>() {
        @Override
        public void onSuccess(Void aVoid) {
          Log.d(TAG, "App data successfully updated");
        }
      })
      .addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
          Log.e(TAG, "Unable to write contents.", e);
        }
      });
}
 
开发者ID:googledrive,项目名称:android-delete,代码行数:21,代码来源:MainActivity.java

示例12: loadContents

import com.google.android.gms.drive.DriveContents; //导入依赖的package包/类
private Task<Void> loadContents(DriveFile file) {
    mGroceryListFile = file;
    Task<DriveContents> loadTask =
            getDriveResourceClient().openFile(file, DriveFile.MODE_READ_ONLY);
    return loadTask.continueWith(new Continuation<DriveContents, Void>() {
        @Override
        public Void then(@NonNull Task<DriveContents> task) throws Exception {
            Log.d(TAG, "Reading file contents");
            mDriveContents = task.getResult();
            InputStream inputStream = mDriveContents.getInputStream();
            String groceryListStr = ConflictUtil.getStringFromInputStream(inputStream);

            mEditText.setText(groceryListStr);
            return null;
        }
    });
}
 
开发者ID:googledrive,项目名称:android-conflict,代码行数:18,代码来源:MainActivity.java

示例13: doInBackground

import com.google.android.gms.drive.DriveContents; //导入依赖的package包/类
/**
 * Opens contents for the given file, executes the editing tasks, saves the
 * metadata and content changes.
 */
@Override
protected Boolean doInBackground(DriveId... params) {
    DriveFile file = params[0].asDriveFile();
    try {
        DriveContents contents =
            Tasks.await(driveResourceClient.openFile(file, DriveFile.MODE_WRITE_ONLY));

        Changes changes = edit(contents);
        MetadataChangeSet changeSet = changes.getMetadataChangeSet();
        DriveContents updatedContents = changes.getDriveContents();

        if (changeSet != null) {
            Tasks.await(driveResourceClient.updateMetadata(file, changeSet));
        }

        if (updatedContents != null) {
            Tasks.await(driveResourceClient.commitContents(updatedContents, changeSet));
        }
    } catch (ExecutionException | InterruptedException e) {
        Log.e(TAG, "Error editing DriveFile.", e);
        return false;
    }

    return true;
}
 
开发者ID:googledrive,项目名称:android-quickeditor,代码行数:30,代码来源:EditDriveFileAsyncTask.java

示例14: sync_getFileContents

import com.google.android.gms.drive.DriveContents; //导入依赖的package包/类
/**
 * Gets the file contents, see {@link DriveContents}
 * 
 * @param driveFile	The Drive file.
 * @param openMode	The open mode. See {@link DriveFile}
 * @param downloadProgressListener	If set, opening progress
 * 									information can be show.
 * @returns The Drive file contents, see {@link DriveContents}
 */
public DriveContents sync_getFileContents(DriveFile driveFile, int openMode, 
		DownloadProgressListener downloadProgressListener) throws TBDriveException {
	
	DriveContentsResult result = null;
	if(downloadProgressListener!=null) {
		result = driveFile.open(getGoogleApiClient(), openMode, downloadProgressListener).await();
	}else{
		result = driveFile.open(getGoogleApiClient(), openMode, null).await();	        
	}
	
	if (!result.getStatus().isSuccess()) {
           //Display an error saying file can't be opened
       	Log.e(TAG, "Problem opening the file [" + result.getStatus().getStatusMessage() + "].");
       	throw new TBDriveException("Problem opening the file [" + result.getStatus().getStatusMessage() + "].");
           
       }
	
       //DriveContents object contains pointers to the byte stream
       return result.getDriveContents();
}
 
开发者ID:javocsoft,项目名称:javocsoft-toolbox,代码行数:30,代码来源:TBDrive.java

示例15: drive_replaceTextOfFile

import com.google.android.gms.drive.DriveContents; //导入依赖的package包/类
/**
 * Replaces the text content of the file with the specified new string content data.
 * 
 * <b>NOTE</b>:<br><br>
 * 	To use this method, Drive file must be opened in MODE_WRITE_ONLY.
 * 
 * @param driveContent	The Drive file contents, see {@link DriveContents}
 * @param data
 * @return The modified contents.
 * @throws IOException	In case of any error or bad open mode.
 */
public synchronized DriveContents drive_replaceTextOfFile(DriveContents driveContent, String data) throws IOException {
	
	Writer writer = null;
	
	if(driveContent.getMode()==DriveFile.MODE_WRITE_ONLY) {
		try {
		    ParcelFileDescriptor parcelFileDescriptor = driveContent.getParcelFileDescriptor();
		    
		    //Append new data content
		    FileOutputStream fileOutputStream = new FileOutputStream(parcelFileDescriptor.getFileDescriptor());
		    writer = new OutputStreamWriter(fileOutputStream);
		    writer.write(data);		    
			
		} finally {
			try {			
				writer.close();
			}catch(Exception e){}
		}		
	}else{
		throw new IOException("Replacing whole content of a file needs MODE_WRITE_ONLY open mode.");
	}
	
	//Returns the modified contents
	return driveContent;
}
 
开发者ID:javocsoft,项目名称:javocsoft-toolbox,代码行数:37,代码来源:TBDrive.java


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