0
mFileId = (DriveId) data.getParcelableExtra(
            OpenFileActivityBuilder.EXTRA_RESPONSE_DRIVE_ID);
Log.e("file id", mFileId.getResourceId() + "");
DriveFile file = mFileId.asDriveFile();
try {
    results =  file.open(mGoogleApiClient, DriveFile.MODE_READ_ONLY, null).await();//this is to return a driveContent object

DriveContents contents = results.getDriveContents();

This is the error it gives when that file should be opened in readonly mode, but the file is already open in readonly mode

InputStream in=contents.getInputStream();

Warren Sergent
  • 2,542
  • 4
  • 36
  • 42
Hamid Javed
  • 51
  • 1
  • 5

1 Answers1

0

Try to use java.io.File.setReadOnly() to set a file to readonly. Also check whether the file has been created or exists first and then set the read only flag.

File file = new File("C:/path/file.txt");
    if (file.exists()) {
        file.setReadOnly();
    } else {
        System.out.println("File does not exists.");
    }

Check these related threads and this example from the documentation:

Community
  • 1
  • 1
abielita
  • 13,147
  • 2
  • 17
  • 59