One, exposing private files
1. There is an application that takes a private file, and the requirement is to expose this private file.
2. Write a subclass of ContentProvider
3. Define matching rules
* Define the Urimatcher of the matching device
* Define matching rules Murimatcher.adduri ("com.xunfang.content", "filename", SUCCESS);
4. Overriding the OpenFile method
5. Declare the content provider node in the manifest file (<provider android:name= "Com.xunfang.contentprovider.DBContentProvider" Android: authorities= "com.xunfang.db"/>)
6. Accessing the file
//gets a content parser
contentresolver resolver = Getcontentresolver ();
//set URI
uri uri = Uri.parse (" Content://com.xunfang.login/info.txt ");
try {
InputStream is = Resolver.openinputstream (URI);
bufferedreader br = new BufferedReader (new InputStreamReader (IS));
string info = br.readline ();
tvinfo.settext (info);
} catch (Exception e) {
e.printstacktrace ();
}
two. private data access to a database
1. There is an application with a private database, and the requirement is to expose this private database.
2. Write a subclass of ContentProvider
3. Define matching rules
* Define the Urimatcher of the matching device
* Define matching rules Murimatcher.adduri ("Com.xunfang.content", "info", SUCCESS);
4. According to the business needs to achieve additions and deletions to the method
5. Declaring the content provider node in the manifest file
How Android accesses private data (5)