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


Java Metadata.getDriveId方法代码示例

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


在下文中一共展示了Metadata.getDriveId方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onResult

import com.google.android.gms.drive.Metadata; //导入方法依赖的package包/类
@Override
public void onResult(@NonNull DriveApi.MetadataBufferResult result) {
    if(!result.getStatus().isSuccess()) {
        Log.w(LOG_TAG, "Retrieving files received error");
    }
    else {
        for(Metadata data : result.getMetadataBuffer()) {
            String fileName = data.getTitle();
            if(fileName != null && fileName.equalsIgnoreCase(SAVED_DATA)) {
                mDriveId = data.getDriveId();
                break;
            }
        }
    }
    if(mDriveId!=null) {
        read();
    }
    else {
        mListener.onSyncFailed(CA.NO_DATA);
    }
    result.release();
}
 
开发者ID:zhuqianqian,项目名称:Passbook,代码行数:23,代码来源:DriveSyncService.java

示例2: findChild

import com.google.android.gms.drive.Metadata; //导入方法依赖的package包/类
public static DriveId findChild(GoogleApiClient mClient, String title, DriveFolder baseFolder) {
    ArrayList<Filter> fltrs = new ArrayList<>();
    fltrs.add(Filters.eq(SearchableField.TRASHED, false));
    if (title != null) fltrs.add(Filters.eq(SearchableField.TITLE, title));
    Query qry = new Query.Builder().addFilter(Filters.and(fltrs)).build();
    DriveApi.MetadataBufferResult rslt = (baseFolder == null) ?
            Drive.DriveApi.query(mClient, qry).await() :
            baseFolder.queryChildren(mClient, qry).await();
    if (rslt.getStatus().isSuccess()) {
        MetadataBuffer mdb = null;
        try {
            mdb = rslt.getMetadataBuffer();
            if (mdb != null) {
                for (Metadata md : mdb) {
                    if (md == null) continue;
                    return md.getDriveId();      // here is the "Drive ID"
                }
            }
        } finally {
            if (mdb != null) mdb.close();
        }
    }
    return null;
}
 
开发者ID:davidgraeff,项目名称:Android-NetPowerctrl,代码行数:25,代码来源:GDrive.java

示例3: doInBackground

import com.google.android.gms.drive.Metadata; //导入方法依赖的package包/类
@Override
protected String doInBackground(Void... params) {
    DriveHelper helper = new DriveHelper(mGoogleApiClient);
    StringBuilder result = new StringBuilder();
    MetadataBuffer buffer = Drive.DriveApi.getAppFolder(mGoogleApiClient)
            .listChildren(mGoogleApiClient).await().getMetadataBuffer();
    try {
        result.append("found ").append(buffer.getCount())
                .append(" file(s):").append(EOL)
                .append("----------").append(EOL);

        for (Metadata m : buffer) {
            DriveId id = m.getDriveId();
            result.append("Name: ").append(m.getTitle()).append(EOL);
            result.append("MimeType: ").append(m.getMimeType()).append(EOL);
            result.append(id.encodeToString()).append(EOL);
            result.append("LastModified: ").append(m.getModifiedDate().getTime())
                    .append(EOL);
            String content = helper.getContentsFromDrive(id);
            result.append("--------").append(EOL)
                    .append(content).append(EOL);
            result.append("--------");
        }
    } catch (IOException io) {
        result.append("Exception fetching content").append(EOL);
    } finally {
        buffer.close();
    }
    return result.toString();
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:31,代码来源:ViewFilesInAppFolderActivity.java

示例4: ServerItem

import com.google.android.gms.drive.Metadata; //导入方法依赖的package包/类
public ServerItem(Metadata metadata) {
    uuid = metadata.getTitle().split("\\.")[0]; // Get only the file name, not the extension
    driveId = metadata.getDriveId();

    CustomPropertyKey key = new CustomPropertyKey(GoogleDriveSyncManager.PROPERTY_TRASHED, CustomPropertyKey.PRIVATE);
    Map<CustomPropertyKey, String> customProperties = metadata.getCustomProperties();
    deleted = customProperties.containsKey(key) && GoogleDriveSyncManager.PROPERTY_TRASHED_TRUE.equals(customProperties.get(key));
}
 
开发者ID:BoD,项目名称:bikey,代码行数:9,代码来源:ServerItem.java

示例5: getOrCreateDriveFolder

import com.google.android.gms.drive.Metadata; //导入方法依赖的package包/类
/**
 * search on a particualr folder or root
 */
public static DriveId getOrCreateDriveFolder(GoogleApiClient mGoogleApiClient,DriveId baseFolderId, String targetFolder) throws ImportExportException {
    DriveFolder baseFolder=null;
    if (baseFolderId!=null) {
        baseFolder=Drive.DriveApi.getFolder(mGoogleApiClient, baseFolderId);
        //DriveResource.MetadataResult r = baseFolder.getMetadata(mGoogleApiClient).await();
    }
    if (baseFolder==null) {
        baseFolder=Drive.DriveApi.getRootFolder(mGoogleApiClient);
    }

    DriveId folder = null;
    if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) {
        Query query = new Query.Builder()
                .addFilter(Filters.eq(SearchableField.TITLE, targetFolder))
                .addFilter(Filters.eq(SearchableField.TRASHED, false))
                .addFilter(Filters.eq(SearchableField.MIME_TYPE, "application/vnd.google-apps.folder"))
                .build();
        // fire the query
        DriveApi.MetadataBufferResult rslt =baseFolder.queryChildren(mGoogleApiClient,query).await();
        //DriveApi.MetadataBufferResult rslt = Drive.DriveApi.query(mGoogleApiClient, query).await();
        if (rslt.getStatus().isSuccess()) {
            MetadataBuffer mdb = null;
            try {
                mdb = rslt.getMetadataBuffer();

                for (Metadata md : mdb) {
                    if (md == null || !md.isDataValid() || md.isTrashed()) continue;
                    //   md.getTitle(), md.getDriveId(), ....
                    if (md.getTitle().equals(targetFolder)) {
                        folder = md.getDriveId();
                    }
                }
            } finally {
                if (mdb != null) mdb.close();
            }
        }
        //if not found create it
        if (folder == null) {
            MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
                    .setTitle(targetFolder).build();
            DriveFolder.DriveFolderResult rslt2 = baseFolder.createFolder(mGoogleApiClient, changeSet).await();
            folder = rslt2.getDriveFolder().getDriveId();
        }
        return folder;
    } else {
        throw new ImportExportException(R.string.gdocs_connection_failed);
    }
}
 
开发者ID:emmanuel-florent,项目名称:flowzr-android-black,代码行数:52,代码来源:ApiClientAsyncTask.java

示例6: onCreate

import com.google.android.gms.drive.Metadata; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mLogArea = new TextView(this);

    ApiClientAsyncTask<Void, Void, String> task = new ApiClientAsyncTask<Void, Void, String>(this) {
        @Override
        protected String doInBackgroundConnected(Void[] params) {
            StringBuffer result = new StringBuffer();
            MetadataBuffer buffer = Drive.DriveApi.getAppFolder(getGoogleApiClient())
                    .listChildren(getGoogleApiClient()).await().getMetadataBuffer();

            result.append("found " + buffer.getCount() + " files:\n");
            for (Metadata m: buffer) {
                DriveId id = m.getDriveId();
                DriveFile file = Drive.DriveApi.getFile(getGoogleApiClient(), id);

                Contents contents = file.openContents( getGoogleApiClient(),
                        DriveFile.MODE_READ_ONLY, null).await().getContents();

                FileInputStream is = new FileInputStream(contents.getParcelFileDescriptor().getFileDescriptor());
                try {
                    BufferedReader bf = new BufferedReader(new InputStreamReader(is, Charsets.UTF_8));
                    String line=null; StringBuffer sb=new StringBuffer();
                    while ((line=bf.readLine()) != null ) {
                        sb.append(line);
                    }
                    file.discardContents(getGoogleApiClient(), contents);
                    result.append("*** " + m.getTitle() + "/" + id + "/" + m.getFileSize() + "B:\n   [" + sb.toString() + "]\n");
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            buffer.close();
            return result.toString();
        }

        @Override
        protected void onPostExecute(String s) {
            if (mLogArea != null) {
                mLogArea.append(s);
            }
        }
    };
    task.execute();

}
 
开发者ID:ramonrabello,项目名称:devfestnorte-app,代码行数:48,代码来源:ViewFilesInAppFolderActivity.java

示例7: lookupDriveFile

import com.google.android.gms.drive.Metadata; //导入方法依赖的package包/类
static public DriveFile lookupDriveFile(DriveId driveId, GoogleApiClient apiClient) {
    DriveFile result = null;

    // First, check if ID is valid
    if (driveId != null) {
        Log.d(TAG, "DriveID passed is not null, trying to get the corresponding file");
        try {
            result = Drive.DriveApi.getFile(apiClient, driveId);
            if (result != null)  {
                // check if metadata is ok. For example, if the file has been directly removed from
                // the server, the getFile can return a file that is actually not valid. Hopefully
                // the metadata will get the correct info
                try {
                    DriveResource.MetadataResult metadataResult = result.getMetadata(apiClient).await();
                    if (!metadataResult.getStatus().isSuccess()) {
                        result = null;
                    }
                } catch (Exception ex) {
                    result = null;
                }
            }
        } catch (Exception e) {
            Log.d(TAG, "Saved drive ID "+driveId+" seems to be invalid (message: " +
                    e.getMessage()+"). Ignoring it");
            result = null;
        }
    }

    if (result == null) {
        // search for a file with the expected name (and get the most recent one, if many)
        Log.d(TAG, "DriveID passed is null, looking up for a file named "+DRIVE_FILENAME);
        Metadata metaOfMostRecent = null;
        MetadataBuffer buffer = Drive.DriveApi.getAppFolder(apiClient)
                .listChildren(apiClient).await().getMetadataBuffer();
        Log.d(TAG, "Found "+buffer.getCount()+" files");
        for (Metadata metadata: buffer) {
            if (metaOfMostRecent != null) {
                Log.w(TAG, "Warning, found more than one file named "+DRIVE_FILENAME+
                        " in AppData folder. Using the most recently modified.");
            }
            if (metaOfMostRecent == null || metaOfMostRecent
                    .getModifiedDate().compareTo(metadata.getModifiedDate())<0) {
                metaOfMostRecent = metadata;
            }
        }
        if (metaOfMostRecent != null) {
            driveId = metaOfMostRecent.getDriveId();
            result = Drive.DriveApi.getFile(apiClient, driveId);
        }
        buffer.close();
    }

    return result;
}
 
开发者ID:ramonrabello,项目名称:devfestnorte-app,代码行数:55,代码来源:DriveHelper.java

示例8: sync_getFile

import com.google.android.gms.drive.Metadata; //导入方法依赖的package包/类
/**
 * Looks for the specified file name (or title).<br><br>
 * 
 * <b>Note</b><br>
 *  Only returns the first found file if there is more than one file
 *  with the same filename/title.
 * 
 * @param fileName	The file name or title of the desired file.
 * @returns DriveFile The desired file or null if there is none. See
 * 					  {@link DriveFile}.
 * 
 */
public synchronized DriveFile sync_getFile(String fileName) throws TBDriveException {
	
	DriveFile driveFile = null;
	
    //Look for a file with title/filename
    SortOrder sortOrder = new SortOrder.Builder()
    	.addSortAscending(SortableField.TITLE)
    	.addSortDescending(SortableField.MODIFIED_DATE).build();
    
	Query query = new Query.Builder().addFilter(
			Filters.and(
					Filters.eq(SearchableField.TITLE, fileName)
					, Filters.eq(SearchableField.TRASHED, false)
					//, Filters.eq(SearchableField.MIME_TYPE, "text/plain")    					
					//, Filters.eq(customPropertyKey, "world")
					)
			)
			.setSortOrder(sortOrder)
	        .build();
	
	MetadataBufferResult result = Drive.DriveApi.query(getGoogleApiClient(), query).await();
	
	if (!result.getStatus().isSuccess()) {
        Log.e(TAG, "Problem while retrieving files: '" + result.getStatus().getStatusMessage() + "'");
        result.release();
        throw new TBDriveException("Problem while retrieving files: '" + result.getStatus().getStatusMessage() + "'");         
    }

	Iterator<Metadata> iterator = result.getMetadataBuffer().iterator();            	
	Metadata mData = null;
	while(iterator.hasNext()) {
		mData = iterator.next();
		
		if(!mData.isFolder()){
			driveFile = Drive.DriveApi.getFile(getGoogleApiClient(), mData.getDriveId());
			if(driveFile==null) {
				//Error getting Drive File from id. Should never happen
				Log.e(TAG, "Problem while retrieving file with DriveId: " + mData.getDriveId());
				result.release();
				throw new TBDriveException("Problem while retrieving file with DriveId: " + mData.getDriveId() + ". Not found in Drive!!");
			}         			
		}
		break; //Should only be one.
	}
	result.release();
	
	return driveFile;
}
 
开发者ID:javocsoft,项目名称:javocsoft-toolbox,代码行数:61,代码来源:TBDrive.java

示例9: getDriveFileFromMetadata

import com.google.android.gms.drive.Metadata; //导入方法依赖的package包/类
/**
 * Work method that retrieves a DriveFile from some passed Metadata.
 * @param driveClient the {@link GoogleApiClient} to use for this Drive request
 * @param metadata the Metadata to pull the {@link DriveFile} out of
 * @return the {@link DriveFile} extracted from the passed Metadata
 */
public DriveFile getDriveFileFromMetadata(GoogleApiClient driveClient, Metadata metadata) {

    DriveId driveId = metadata.getDriveId();

    return Drive.DriveApi.getFile(driveClient, driveId);
}
 
开发者ID:akilawickey,项目名称:pinPotha,代码行数:13,代码来源:DriveFio.java

示例10: getDriveFileFromMetadata

import com.google.android.gms.drive.Metadata; //导入方法依赖的package包/类
/**
 * Work method that retrieves a DriveFile from some passed Metadata.
 *
 * @param driveClient the {@link GoogleApiClient} to use for this Drive request
 * @param metadata    the Metadata to pull the {@link DriveFile} out of
 * @return the {@link DriveFile} extracted from the passed Metadata
 */
public DriveFile getDriveFileFromMetadata(GoogleApiClient driveClient, Metadata metadata) {

    DriveId driveId = metadata.getDriveId();

    return Drive.DriveApi.getFile(driveClient, driveId);
}
 
开发者ID:akilawickey,项目名称:pinPotha,代码行数:14,代码来源:DriveFio.java


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