简体   繁体   English

内容提供商如何工作?

[英]How do content providers works?

Well, as far as I kwnow a content provider is a database, and is used to pass data through apps. 好吧,据我所知,内容提供者是一个数据库,用于通过应用程序传递数据。

But this data can be accessed only in the phone that it was saved? 但是只能在已保存的电话中访问此数据吗? Or if I saved some data using the app with phone1, can I retrieve it using the app with phone 2? 或者,如果我使用带电话1的应用程序保存了一些数据,是否可以使用带电话2的应用程序检索数据?

If it can't do the second option, what could I use to do it? 如果它不能执行第二种选择,我该怎么用呢? Thanks. 谢谢。

Content provider is not a database. 内容提供者不是数据库。 You can think this as a layer between your app and underlying data. 您可以将其视为应用程序与基础数据之间的一层。 The data can be in sqlite database, file or something else. 数据可以在sqlite数据库,文件或其他文件中。 Content provider is very useful to access and store your data to database or file. 内容提供者对于访问数据并将其存储到数据库或文件非常有用。 You need this when you use syncadapter or widgets in your app. 在应用程序中使用syncadapter或小部件时,您需要此功能。 Now to answer your question, content provider of your app can be accessed by a different app in your same phone provided you use correct permission. 现在回答您的问题,只要您使用正确的权限,您的应用程序的内容提供商就可以通过同一部手机中的其他应用程序访问。 As I mentioned it's not a database, so answer of second question is not. 正如我提到的,它不是数据库,所以第二个问题的答案不是。 I would recommend you to read about content provider on android developer site to get the basic concepts. 我建议您在android开发人员网站上阅读有关content provider的信息,以获取基本概念。

A content provider component supplies data from one application to others on request. 内容提供商组件应要求将数据从一个应用程序提供给其他应用程序。 Such requests are handled by the methods of the ContentResolver class. 此类请求由ContentResolver类的方法处理。 A content provider can use different ways to store its data and the data can be stored in a database, in files, or even over a network. 内容提供商可以使用不同的方式来存储其数据,并且数据可以存储在数据库,文件中,甚至可以通过网络存储。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM