AI is now very popular, AI will be born some next generation of giant enterprises, all walks of life are fighting for this wind, Baidu CEO did not leave the company’s internal affairs, a head into the AI research team work, Some time ago, Robin Li drove his company’s driverless car, namely 6. All the big companies have important projects in AI, and they are scrambling for the top of the next era. In terms of the Internet of things, to do good is millet, millet, filling, brought together more than 70 intelligent hardware companies, formed the millet filling, millet in the future will be in the Internet of things will be a big winner, router, we know the millet millet hand ring, millet sweeping robot is that more than 70 companies in production and research and development, LeiJunTai foresight. Ok, without further ado, let’s get down to business and record the requirements for using storage in version 7.0.


Recently, I updated the APP online according to the demand. At first, I did not adapt the models above 7.0, so the 7.0 mobile phone could not jump to the APP installation interface. Said, the android system development is more and more useful, the user experience is getting better and better, the users' privacy also was normative protection, as we all know from the beginning of the 6.0 system Google began using mobile phones for app permissions for certain constraints, for more than 6.0 permissions apply for I will not say, for permission to apply for, I have written a framework, which is very convenient to use in the items. Let's talk about the "FileProvider" added to storage usage in 7.0. Let's take a look at the usage and read the official documentation.Copy the code

# # # # # FileProvider is introduced

FileProvider is a special subclass of ContentProvider that facilitates secure sharing of files associated with an app by creating a content:// Uri for a file instead of a file:/// Uri.

A content URI allows you to grant read and write access using temporary access permissions. When

you create an Intent containing a contentURI, in

order to send the content URI to a client app, you can also call Intent.setFlags() to add permissions. These permissions are available to the client app for as long as the stack for a receiving Activity is active. For an Intent going to a Service, the permissions are available as long as the Service is running.

In comparison, to control access to a file:/// Uri you have to modify the file system permissions of the underlying file. The permissions you provide become available to any app, and remain in effect until you change them. This level of access is fundamentally insecure.

The increased level of file access security offered by a content URI makes FileProvider a key part of Android’s security infrastructure.

This overview of FileProvider includes the following topics:

FileProvider is a special ContentProvider subclass that facilitates the secure sharing of files associated with an application by creating a Content:/ / Uri instead of a File :/ / Uri for the file.

Content URIs allow you to grant read and write access using temporary access rights. When you create the intent that contains the content URI, to send the content URI to the client application, you can also call Intent.setFlags () to add permissions. Client applications can use these permissions as long as the receiving active stack is active. To obtain a service, permissions are available as long as the service is running.

In contrast, to control file:/ / / URIs on files, you must change the file system permissions on the underlying files. The permissions you provide are available to any application and remain in effect until you change them. This level of access is basically insecure.

The increased security of file access provided by content URIs makes FileProviders a critical part of The Android security infrastructure.

1. Add code to the program manifest file:

<manifest>
...
<application>
   ...
   <provider  android:name= "android.support.v4.content.FileProvid"  
        android:authorities="com.mydomain.fileprovider"
        android:exported="false"
        android:grantUriPermissions="true"> <! -- meta --> <meta -- data Android :name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/file_path" />
    </provider>
    ...
</application>
</manifest>Copy the code

Com.mydomain is replaced with its own project package name, unique.

2. Create an XML folder in the res directory and create an XML file “file_path” under the file.

3. Write the file_path file

<? xml version="1.0" encoding="utf-8"? > <resources> <paths> <root-path name="download" path=""/>
</paths>
</resources>Copy the code

Layer 3 is configured differently depending on the storage path we use.

(1) When we use context.getfilesdir () to get the path we should set it to <files-path name="name" path="path"/> (2) <cache-path name= when we use getCacheDir() to obtain the storage path"name" path="path"/ > (3) the use of the Environment. External.getexternalstoragedirectory () to get the directory, < root - path name ="download" path=""/ >, the path value can be null, null on behalf of the authorized the all files in the directory, the name must write, or you will quote serious abnormal. (4) using the Context getExternalCacheDir () < external cache - the path name ="name" path="path"/ > (5) using the Context. GetExternalFilesDir (null) configured to external files - path name ="name" path="path" />Copy the code

In addition, we have changed the following code when jumping to the installation directory:

public static void install(Context context,String target) { File file = new File(target); Intent intent = new Intent(Intent.ACTION_VIEW); Intent.setflags (intent.flag_activity_new_task); // Intent.setflags (intent.flag_activity_new_task);if(build.version.sdk_int >=24) {// Check whether the VERSION is higher than 7.0 // parameter 1 context, Parameter 2 Provider host address and consistent parameters in the configuration file of 3 Shared file Uri apkUri = FileProvider. GetUriForFile (context,"com.gzzhe.zhhwlkj.zigou.fileprovider", file); Intent.addflags (intent.flag_grant_read_uri_permission); intent.flag_grant_read_uri_permission); intent.flag_grant_read_uri_permission intent.setDataAndType(apkUri,"application/vnd.android.package-archive");
    }else{
        intent.setDataAndType(Uri.fromFile(file),
                "application/vnd.android.package-archive");
    }
    context.startActivity(intent);
}Copy the code

Well, that’s all for the introduction.