在本教程之后,我将此代码粘贴到我的主要活动中:
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
if (connectionResult.hasResolution()) {
try {
connectionResult.startResolutionForResult(this, RESOLVE_CONNECTION_REQUEST_CODE);
} catch (IntentSender.SendIntentException e) {
// Unable to resolve, message user appropriately
}
} else {
GooglePlayServicesUtil.getErrorDialog(connectionResult.getErrorCode(), this, 0).show();
}
}
Run Code Online (Sandbox Code Playgroud)
我最终必须导入buncha库,但我仍然无法修复此错误:
RESOLVE_CONNECTION_REQUEST_CODE cannot be resolved to a variable
Run Code Online (Sandbox Code Playgroud)
有任何想法吗???我无法弄清楚哪个库包含此常量...
我正在使用Google Drive.Api,以便将用户的应用数据与用户驱动器帐户同步.
用户数据库采用sqlite数据库格式.我已成功将文件以二进制形式上传到驱动器,但无法从应用程序中下载文件.
我如何得到文件URl:
final GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(this, Arrays.asList(DriveScopes.DRIVE_FILE));
credential.setSelectedAccountName(accountName);
service = new com.google.api.services.drive.Drive.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential).build();
Query query = new Query.Builder()
.addFilter(Filters.eq(SearchableField.TITLE, "BackupFile"))
.build();
final DriveFolder folder = Drive.DriveApi.getRootFolder(mGoogleApiClient);
folder.queryChildren(mGoogleApiClient, query).setResultCallback(new ResultCallback<DriveApi.MetadataBufferResult>() {
@Override
public void onResult(DriveApi.MetadataBufferResult metadataBufferResult) {
final MetadataBuffer metadataBuffer = metadataBufferResult.getMetadataBuffer();
int iCount = metadataBuffer.getCount();
if (iCount == 1) {
Log.i("Tag", "file was found");
final DriveId myFileId = metadataBuffer.get(0).getDriveId();
final DriveFile file = Drive.DriveApi.getFile(mGoogleApiClient, myFileId);
new Thread(new Runnable() {
@Override
public void run() {
DriveResource.MetadataResult …Run Code Online (Sandbox Code Playgroud) 我收到一个无效的父文件夹错误,我已经看到使用资源ID而不是驱动器ID的解决方案,但这是一个不同的场景.
我正在尝试访问AppFolder,这只是使用GoogleApiClient,如下所示:
this.appFolder = Drive.DriveApi.getAppFolder(mGoogleApiClient);
Run Code Online (Sandbox Code Playgroud)
当我稍后尝试在其中创建文件时,我得到上述错误.
DriveFolder.DriveFileResult fileResult = appFolder.createFile(mGoogleApiClient, changeSet, driveContentsResult.getDriveContents()).await();
Run Code Online (Sandbox Code Playgroud)
然后fileResult.getStatus()给了我错误.
这曾经对我有用.不同的是,我在Google云端硬盘上手动清空了应用的数据(删除隐藏的应用数据).但我没有断开应用程序 - 所以我认为appFolder将继续以相同的方式工作......
到目前为止,唯一的解决方法是卸载应用程序,但这样我就丢失了数据.
这是可重复的.请帮忙.
我在三星Galaxy S4 mini中运行它.KitKat Android.
在应用程序中,我使用GCM进行消息传递和Google Drive API.我认为我得到的错误来自GCM,但我不确定.
这是LogCat:
I/PersonaManager? getPersonaService() name persona_policy
I/GMPM? App measurement is starting up
I/PersonaManager? getPersonaService() name persona_policy
I/MainActivity? onCreate
E/GMPM? getGoogleAppId failed with status: 10
E/GMPM? Uploading is not possible. App measurement disabled
I/PersonaManager? getPersonaService() name persona_policy
Run Code Online (Sandbox Code Playgroud)
我不明白的是GMPM在哪里启动?在我的代码之前,我不会激活Google云端硬盘或GCM.您可以看到GMPM甚至在我的MainActivity之前启动,所以我不确定如何调试它?
我的应用运行正常.它仍然连接到GCM,仍然可以接收消息.仍然连接到Google云端硬盘.仍然检索文件.
但这个错误令我担心.有谁知道它是什么原因,或者我怎么去调试它?
android google-cloud-messaging android-studio google-drive-android-api
我在Android中使用Google表格API v4.
https://developers.google.com/sheets/api/quickstart/android
我需要知道最后一次修改工作表的时间(包括用户); 我需要这个人:
我想做这样的事情:
Spreadsheet spreadsheet = sheetsService.spreadsheets().get(spreadsheetId).setIncludeGridData(true).execute();
Date date = spreadsheet.getProperties().getLastEditDate();
Run Code Online (Sandbox Code Playgroud)
但是,当然,不getLastEditDate()存在这样的属性方法.是否有参数或其他API方法来调用以获取此数据?
更好的方法是获取每个单元格的修改日期......但我会考虑整个电子表格或表格的日期.
google-api google-sheets google-drive-android-api google-sheets-api
我正在使用Android文件选择并从应用程序存储(图像,视频,文档)中选择文件.我有一个函数"getPath".我从uri得到路径.我对图库图像或下载文档没有任何问题.但是当我从谷歌驱动器中选择一个文件时,我无法获得路径.这是google drive uri"content://com.google.android.apps.docs.storage/document/acc%3D25%3Bdoc%3D12"你能帮我解决一下吗?
这也是我的"getPath"功能.
public static String getPath(final Context context, final Uri uri) {
// check here to KITKAT or new version
final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
// DocumentProvider
if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
// ExternalStorageProvider
if (isExternalStorageDocument(uri)) {
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
final String type = split[0];
if ("primary".equalsIgnoreCase(type)) {
return Environment.getExternalStorageDirectory() + "/"
+ split[1];
}
}
// DownloadsProvider
else if (isDownloadsDocument(uri)) {
final String id = DocumentsContract.getDocumentId(uri);
final …Run Code Online (Sandbox Code Playgroud) 我正在使用新的Google云端硬盘Android API,我可以连接,并执行所有允许我这样做的操作,但为了使用SpreadsheetService,我需要从已登录的用户中提取accountName/email.
我怎么做?
这是我连接Google Drive API的代码.它工作正常.
private void connect() {
if (isGooglePlayServicesAvailable()) {
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
// And, connect!
if (!mGoogleApiClient.isConnecting() && !mGoogleApiClient.isConnected()) {
mGoogleApiClient.connect();
writeLog("Connecting...");
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是我使用SpreadsheetService API的地方,但我需要帐户名来获取令牌.
String accountName = "???"; // how do I get this From GoogleClientApi / mGoogleApiClient ?
String accessToken = GoogleAuthUtil.getTokenWithNotification(GDriveActivity.this, accountName, scope, null);
SpreadsheetService service = new SpreadsheetService("v1");
Run Code Online (Sandbox Code Playgroud)
我试过这个添加这个:
String accountName = …Run Code Online (Sandbox Code Playgroud) 嗨,我正在尝试实现类似于 whatsapp 的备份功能,但是当我在逆向工程 whatsapp 清单代码后遇到它时。以下是观察结果, android:allowBackup="false" 这意味着它不使用默认的 AutoBackup 功能或任何备份代理
而且我需要有无限的存储限制,不像 AutoBackup 小于 25mb,
例如:目前我的 whatsapp 备份大小为 112mb
android drive google-drive-api android-backup-service google-drive-android-api
我正在将我的应用程序从已弃用的 Google Drive Android API 迁移到 Drive Rest API。我使用新包实现了所需的行为,并且在模拟器中一切正常 - 应用程序要求访问用户的云端硬盘并让它上传文件。当我开始在真实设备上测试它时,我收到此错误:
超出了未经身份验证的使用的每日限制。继续使用需要注册
我已经在https://console.developers.google.com中配置了与旧库配合良好的项目(它需要 ../auth/drive.file 范围)。根据迁移文档- 旧配置应无需更改即可与新库一起使用。
此错误还有哪些其他原因?
我的应用程序要求用户选择一个 Google Drive 文件夹,以便以后可以将文件保存到选定的文件夹中。
到目前为止,它使用 Google Drive Android API 的文件夹选择器 UI,但现在已弃用并关闭。迁移说明建议使用存储访问框架(又名 SAF)来替换以前可用的文件选取器 UI。
问题是,当我尝试使用 ACTION_OPEN_DOCUMENT_TREE 操作启动 SAF UI 时,Google Drive 没有显示。另一个 Stackoverflow 帖子表明SAF不支持选择 Google Drive 文件夹,这很奇怪,因为它是一个非常重要和基本的功能。
有什么方法可以为 Google Drive 实现文件夹选择器 UI,而不必自己从头开始构建它?
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivityForResult(intent, 3);
Run Code Online (Sandbox Code Playgroud) android google-drive-api storage-access-framework google-drive-android-api google-drive-picker