當前位置: 首頁>>代碼示例>>Java>>正文


Java DriveId類代碼示例

本文整理匯總了Java中com.google.android.gms.drive.DriveId的典型用法代碼示例。如果您正苦於以下問題:Java DriveId類的具體用法?Java DriveId怎麽用?Java DriveId使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DriveId類屬於com.google.android.gms.drive包,在下文中一共展示了DriveId類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: saveDriveFile

import com.google.android.gms.drive.DriveId; //導入依賴的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: getContentsFromDrive

import com.google.android.gms.drive.DriveId; //導入依賴的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: createEmptyDriveFile

import com.google.android.gms.drive.DriveId; //導入依賴的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

示例4: getDriveFile

import com.google.android.gms.drive.DriveId; //導入依賴的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

示例5: onActivityResult

import com.google.android.gms.drive.DriveId; //導入依賴的package包/類
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    switch (requestCode) {
        case RESOLVE_CONNECTION_REQUEST_CODE:
            if (resultCode == RESULT_OK) {
                mGoogleApiClient.connect();
            }
            break;

        case 120:

            DriveId driveId = data.getParcelableExtra(OpenFileActivityBuilder.EXTRA_RESPONSE_DRIVE_ID);


            new ReadWriteAsync(driveId).execute();

            break;
    }
}
 
開發者ID:claudiodegio,項目名稱:dbsync,代碼行數:21,代碼來源:TestGDriveActivity.java

示例6: onCreate

import com.google.android.gms.drive.DriveId; //導入依賴的package包/類
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addApi(Drive.API)
            .addScope(Drive.SCOPE_FILE)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();

    ButterKnife.bind(this);

    mMainHandler = new Handler();

    mMainHandler.post(new UpdateCurrentTime());

    String driveId = getPreferences(Context.MODE_PRIVATE).getString(DRIVE_ID_FILE, null);

    if (driveId != null) {
        mDriveId = DriveId.decodeFromString(driveId);
    }
}
 
開發者ID:claudiodegio,項目名稱:dbsync,代碼行數:24,代碼來源:BaseMainDbActivity.java

示例7: onReceive

import com.google.android.gms.drive.DriveId; //導入依賴的package包/類
@Override
public void onReceive(Context context, Intent intent) {
    final DriveId driveId = intent.getParcelableExtra(GDriveEventService.BUNDLE_DRIVEID);

    Log.i(TAG, "onReceive completion event for driveID:" + driveId.encodeToString());

    if (driveId.equals(mDriveId)) {
        result =  intent.getIntExtra(GDriveEventService.BUNDLE_SUCCESS, -1);
        synchronized (this) {
            notify();
        }
    }
}
 
開發者ID:claudiodegio,項目名稱:dbsync,代碼行數:14,代碼來源:GDriveCloudProvider.java

示例8: onActivityResult

import com.google.android.gms.drive.DriveId; //導入依賴的package包/類
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
        case AppConstants.EXPORT_RESOLVE_CONNECTION_REQUEST_CODE:
            if (resultCode == RESULT_OK) {
                mGoogleApiClient.connect();
            }
            break;
        case AppConstants.EXPORT_CREATOR_REQUEST_CODE:
            if (resultCode == RESULT_OK) {
                DriveId driveFileId = (DriveId) data.getParcelableExtra(
                        OpenFileActivityBuilder.EXTRA_RESPONSE_DRIVE_ID);
                writeDataExportToFile(driveFileId);
            }
            break;
        default:
            super.onActivityResult(requestCode, resultCode, data);
            break;
    }
}
 
開發者ID:robertsimoes,項目名稱:Flow,代碼行數:22,代碼來源:TheHubActivity.java

示例9: doInBackgroundConnected

import com.google.android.gms.drive.DriveId; //導入依賴的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

示例10: onActivityResult

import com.google.android.gms.drive.DriveId; //導入依賴的package包/類
@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
            case AppConstants.EXPORT_RESOLVE_CONNECTION_REQUEST_CODE:
                if (resultCode == RESULT_OK) {
//                    mGoogleApiClient.connect();
                }
                break;
            case AppConstants.EXPORT_CREATOR_REQUEST_CODE:
                if (resultCode == RESULT_OK) {
                    DriveId driveFileId = (DriveId) data.getParcelableExtra(
                            OpenFileActivityBuilder.EXTRA_RESPONSE_DRIVE_ID);
                    writeDataExportToFile(driveFileId);
                }
                break;
            default:
                super.onActivityResult(requestCode, resultCode, data);
                break;
        }
    }
 
開發者ID:tortuvshin,項目名稱:yield,代碼行數:22,代碼來源:TheHubActivity.java

示例11: onActivityResult

import com.google.android.gms.drive.DriveId; //導入依賴的package包/類
@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    switch (requestCode) {

        case REQUEST_CODE_CREATOR:
            // Called after a file is saved to Drive.
            if (resultCode == RESULT_OK) {
                Log.i(TAG, "Backup successfully saved.");
                Toast.makeText(this, "Backup successufly loaded!", Toast.LENGTH_SHORT).show();
            }
            break;

        case REQUEST_CODE_OPENER:
            if (resultCode == RESULT_OK) {
                DriveId driveId = data.getParcelableExtra(
                        OpenFileActivityBuilder.EXTRA_RESPONSE_DRIVE_ID);
                //Toast.makeText(this, driveId.toString(), Toast.LENGTH_SHORT).show();
                DriveFile file = driveId.asDriveFile();
                importFromDrive(file);
            }
    }
}
 
開發者ID:prof18,項目名稱:Database-Backup-Restore,代碼行數:23,代碼來源:MainActivity.java

示例12: ServiceConnected

import com.google.android.gms.drive.DriveId; //導入依賴的package包/類
@Override
protected void ServiceConnected () {
    //File already loaded
    if (mFile != null)
        return;

    Log.i("TextEditor", "Loading content after connection");

    Intent intent = getIntent();
    //File opened from history
    if (intent.hasExtra(INTENT_FILE_ID)) {
        long fileId = intent.getLongExtra(INTENT_FILE_ID, -1);
        File file = filesHelper.GetItem(fileId);
        OpenFile(file);
        return;
    }
    //File opened from drive dialog
    if (intent.hasExtra(INTENT_DRIVE_ID)) {
        DriveId driveId = intent.getParcelableExtra(INTENT_DRIVE_ID);
        OpenDriveFile(driveId);
        return;
    }
}
 
開發者ID:rkkr,項目名稱:drive-notepad,代碼行數:24,代碼來源:TextEditor.java

示例13: GetItem

import com.google.android.gms.drive.DriveId; //導入依賴的package包/類
public File GetItem(DriveId driveId) {
    SQLiteDatabase db = dbHelper.getReadableDatabase();

    Cursor cursor = db.query(
            DBContracts.FileEntry.TABLE_NAME,
            null,
            DBContracts.FileEntry.COLUMN_NAME_DRIVE_ID + " = ?",
            new String[]{driveId.encodeToString()},
            null,
            null,
            null
    );

    if (cursor.getCount() != 1)
        return null;

    cursor.moveToFirst();
    File file = CursorToFile(cursor);
    cursor.close();

    return file;
}
 
開發者ID:rkkr,項目名稱:drive-notepad,代碼行數:23,代碼來源:FileHelper.java

示例14: DownloadFile

import com.google.android.gms.drive.DriveId; //導入依賴的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

示例15: UploadFileExisting

import com.google.android.gms.drive.DriveId; //導入依賴的package包/類
private void UploadFileExisting(final DriveId driveId, final String contents, final String fileName, final OnFileUploaded callback) {
    driveId.asDriveFile().open(getApiClient(), DriveFile.MODE_WRITE_ONLY, null).setResultCallback(new ResultCallback<DriveApi.DriveContentsResult>() {
        @Override
        public void onResult(DriveApi.DriveContentsResult driveContentsResult) {
            Utils.writeToOutputStream(driveContentsResult.getDriveContents().getOutputStream(), contents);

            MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
                    .setTitle(fileName)
                    .setPinned(true)
                    .build();

            driveContentsResult.getDriveContents().commit(getApiClient(), changeSet).setResultCallback(new ResultCallback<Status>() {
                @Override
                public void onResult(Status result) {
                    if (result.getStatus().isSuccess())
                        callback.onFileUploaded(driveId);
                    else
                        callback.onFileUploaded(null);
                    activeOperations = false;
                }
            });
        }
    });
}
 
開發者ID:rkkr,項目名稱:drive-notepad,代碼行數:25,代碼來源:DriveService.java


注:本文中的com.google.android.gms.drive.DriveId類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。