Set the If-Match
HTTP header:
final Update update = mService.files().update(mDriveFile.getId(), mDriveFile, byteContent);
final HttpHeaders headers = update.getRequestHeaders();
headers.setIfMatch(mDriveFile.getEtag());
update.setRequestHeaders(headers);
mDriveFile = update.execute();
In case the document has changed meanwhile, the update will get rejected with a response something like:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 412 Precondition Failed
{
"code": 412,
"errors": [
{
"domain": "global",
"location": "If-Match",
"locationType": "header",
"message": "Precondition Failed",
"reason": "conditionNotMet"
}
],
"message": "Precondition Failed"
}