App manifest file. Device compatibility. Multiple APK support. Tablets, large screens, and foldables. Build responsive UIs.
Build for foldables. Getting started. Handling data. User input. Watch Face Studio. Health services. Creating watch faces. Android TV. Build TV Apps. Build TV playback apps. Help users find content on TV. Recommend TV content.
Watch Next. Build TV games. Build TV input services. TV Accessibility. Android for Cars. Build media apps for cars. Build navigation, parking, and charging apps for cars. Android Things. Supported hardware. Advanced setup. Build apps. Create a Things app. Communicate with wireless devices.
Configure devices. Interact with peripherals. Build user-space drivers. Manage devices. Create a build. Push an update. Chrome OS devices. App architecture. Architecture Components. UI layer libraries. View binding. Data binding library. Lifecycle-aware components. Android ships with a number of content providers that store common data such as contact informations, calendar information, and media files. These classes provide simplified methods of adding or retrieving data from these content providers.
For information about how to use a content provider, see the Content Providers developer guide. Sign up to join this community. The best answers are voted up and rise to the top. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Learn more. Achieve proper frame pacing. Frame pacing in Vulkan. Integrate Android Performance Tuner. Output audio. Manage memory. Use prebuilt or turnkey game engines.
Develop with Defold. Develop with Godot. Develop with Unity. Use Android Performance Tuner. Game best practices. Maximize device availability.
Art assets. OpenGL and Vulkan. Game Mode. Best practices. Building effective unit tests. Automating UI tests. Testing app component integrations. Android Vitals. Optimizing for Battery Life. System tracing. Build and test apps for accessibility. Advanced topics. Protecting against security threats with SafetyNet.
Build for Billions. Build for Enterprise. App feedback. Device management. Dedicated devices. Android versions. Android Developers. Manifest To implement a custom document provider, add the following to your application's manifest: A target of API level 19 or higher. The attribute android:name set to the name of your DocumentsProvider subclass, which is its class name, including package name: com.
The attribute android:authority attribute, which is your package name in this example, com. The attribute android:exported set to "true". You must export your provider so that other apps can see it. The attribute android:grantUriPermissions set to "true". This setting allows the system to grant other apps access to content in your provider.
For a discussion about how these other apps can persist their access to content from your provider, see Persist permissions. By default a provider is available to everyone. Adding this permission restricts your provider to the system. This restriction is important for security. An intent filter that includes the android. The SAF provides these contract classes for you, so you don't need to write your own: DocumentsContract. Document DocumentsContract. Gallery, Drive. Kotlin override fun queryDocument documentId: String?
Kotlin override fun openDocumentThumbnail documentId: String? The client is done writing. Time to update the server. Building intelligent escalation chains for modern SRE. Featured on Meta. Now live: A fully responsive profile. Reducing the weight of our footer. Linked Related Hot Network Questions. Question feed. Stack Overflow works best with JavaScript enabled. To show only the types of files that your app supports, specify a MIME type. File management and media-creation apps typically manage groups of files in a directory hierarchy.
Your app can then access any file in the selected directory and any of its sub-directories. You don't have access to other apps' files that reside outside this user-selected directory.
This user-controlled access allows users to choose exactly what content they're comfortable sharing with your app. After the user has selected a file or directory using the system's file picker, you can retrieve the selected item's URI using the following code in onActivityResult :. By getting a reference to the selected item's URI, your app can perform several operations on the item.
For example, you can access the item's metadata, edit the item in place, and delete the item. Different content providers allow for different operations to be performed on documents—such as copying the document or viewing a document's thumbnail.
To determine which operations a given provider supports, check the value of Document. Your app's UI can then show only the options that the provider supports. When your app opens a file for reading or writing, the system gives your app a URI permission grant for that file, which lasts until the user's device restarts.
Suppose, however, that your app is an image-editing app, and you want users to be able to access the 5 images that they most recently edited, directly from your app. If the user's device has restarted, you'd have to send the user back to the system picker to find the files. To preserve access to files across device restarts and create a better user experience, your app can "take" the persistable URI permission grant that the system offers, as shown in the following code snippet:.
When you have the URI for a document, you gain access to its metadata. This snippet grabs the metadata for a document specified by the URI, and logs it:. By having a reference to a document's URI, you can open a document for further processing.
This section shows examples for opening a bitmap and an input stream. The following code snippet shows how to open a Bitmap file given its URI:. After you open the bitmap, you can display it in an ImageView.
In this snippet, the lines of the file are being read into a string:. If you have the URI for a document and the document's Document.
For example:. The 2 URIs refer to the same underlying item. Using the media store URI, you can more easily access media files from shared storage. On Android 7. To open virtual files, your client app needs to include special logic to handle them. If you want to get a byte representation of the file—to preview the file, for example—you need to request for an alternate MIME type from the documents provider.
After the user makes a selection, use the URI in the results data to determine whether the file is virtual, as shown in the following code snippet:. The following code snippet shows how to check whether a virtual file can be represented as an image, and if so, gets an input stream from the virtual file:. For more information about how to store and access documents and other files, consult the following resources. Content and code samples on this page are subject to the licenses described in the Content License.
App Basics. Build your first app. App resources. Resource types. App manifest file. Device compatibility. Multiple APK support. Tablets, large screens, and foldables. Build responsive UIs. Build for foldables. Getting started.
0コメント