Reputation: 6912
I use below code to open .doc file by call other application.
But I don't want the file be modify.
So I want to set file to read only.
Or any other method to avoid user modify file.
The file format may *.doc, *.docx, *.ppt, *.pptx, *.pdf, *.txt.
File file = new File(FilePath);
String mimetype = ".doc\tapplication/msword";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), mimetype);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Upvotes: 1
Views: 3274
Reputation: 1
Copy the document to a cloud storage site. named doc.docx
Then rename it to doc.docx1
, this is your template. You can copy it and remove the docx1 and edit the copy at will, leaving the template in alone.
Upvotes: 0
Reputation: 40367
You cannot prevent data stored on the external storage from being changed by the user, provided they find an application willing to aid in this - readily available file manager apps for example.
As long as the security model remains intact, data stored in the private storage area of an application can protected either from writing, or from both writing and reading by other applications.
Some applications however are reluctant to attempt to access a file pointed to by an Intent if it is located in a different app's private storage area, even if the file and directory permission bits have been set such that the Android system would allow them to. (For example, at least some versions of GMail refuse to attach a file that is not on the external storage, though they can be tricked into doing so provided the file is world readable.)
Upvotes: 1