Android Google Drive - 文件夹更改侦听器

时间:2014-04-05 20:20:14

标签: android listener google-drive-android-api

我注意到在新的Google Drive API(v2)& Google Play服务(04.03.23)有change listeners to receive notifications whenever a specified file or folder has changes to its contents or metadata。如何在整个appdata文件夹(仅用于应用程序数据的文件夹)中将其用作侦听器进行侦听?感谢您提前提供任何帮助。

DriveFile file = Drive.DriveApi.getFile(mGoogleApiClient, mSelectedFileId);
file.addChangeListener(mGoogleApiClient, changeListener);

DriveFile file = Drive.DriveApi.getFile(mGoogleApiClient, mSelectedFileId);
file.removeChangeListener(mGoogleApiClient, changeListener);

final private Listener<ChangeEvent> changeListener = new Listener<ChangeEvent>() 
 {
 @Override
 public void onEvent(ChangeEvent event) 
     {
     mLogTextView.setText(String.format("File change event: %s", event));
     }
 };

2 个答案:

答案 0 :(得分:2)

您需要在.await().setResultCallback()来电呼叫.addChangeListener.removeChangeListener,以激活它们。这不包含在云端硬盘网站上;我给他们写了post

您可以检查之后调用的返回状态,以确保它已正确设置(在app文件夹上设置监听器似乎不起作用,至少在我的情况下)。

答案 1 :(得分:1)

我找到了解决方案:

DriveFolder folder = Drive.DriveApi.getFolder(mGoogleApiClient,Drive.DriveApi.getRootFolder(googleApiClient).getDriveId());
folder.addChangeListener(mGoogleApiClient, changeListener);