简体   繁体   English

Android上的网络可访问性和内容提供商

[英]Network Accessibility and Content Providers on android

I recently have gotten very interested in android development. 我最近对android开发非常感兴趣。 I have this application that needs to be able to store user accounts onto a database. 我有这个应用程序,它需要能够将用户帐户存储到数据库中。 How do I go about making this database network accessible, so users of my application can access their account? 如何使该数据库网络可访问,以便我的应用程序用户可以访问其帐户? I've been looking into this and I think that content providers are one method of solving this problem. 我一直在研究,我认为内容提供商是解决此问题的一种方法。 However, I don't know anything about content providers so some clarification would be great. 但是,我对内容提供商一无所知,因此需要进行一些澄清。 Anyways here are my questions straightforward: 无论如何,这是我的简单问题:

How do I go about making a database network accessible so users of my android application can access their account? 如何使数据库网络可访问,以便我的android应用程序的用户可以访问其帐户?

What is a content provider and are they free? 什么是内容提供商,他们免费吗?

Thanks for your time and I appreciate the help. 感谢您的宝贵时间,感谢您的帮助。

Good questions, but too broad and open-ended. 好问题,但范围太广且开放。 Also, I find it hard to understand 另外,我觉得很难理解

You have an application that needs to be able to store user accounts onto a database. 您有一个需要能够将用户帐户存储到数据库中的应用程序。 Where will the database be, on the web or on the device? 该数据库在Web上还是在设备上将位于何处? Do you want to be able to access a web database from the device? 您是否希望能够从设备访问Web数据库? Do you intend to store the user accounts on the device? 您打算将用户帐户存储在设备上吗?

If you have a web-based database, you have to provide a web server to get data from the database and offer it to your Android app. 如果您有基于Web的数据库,则必须提供Web服务器以从数据库中获取数据并将其提供给Android应用。 There are many ways to do this. 有很多方法可以做到这一点。

A content provider is one of the four main building blocks of an Android app (the others being activity, service, and broadcast receiver). 内容提供商是Android应用程序的四个主要组成部分之一(其他是活动,服务和广播接收者)。 Content providers provide a standard interface between local data and other components, including components in other apps. 内容提供商在本地数据和其他组件(包括其他应用程序中的组件)之间提供标准接口。 A content provider can handle files, databases, and even internal data structures you build within the provider, but most content providers encapsulate an SQLite database. 内容提供程序可以处理您在该提供程序中构建的文件,数据库,甚至内部数据结构,但是大多数内容提供程序都封装了SQLite数据库。

In regard to transferring data between a server and the device, content providers often represent the location of the local data. 关于在服务器和设备之间传输数据,内容提供者通常代表本地数据的位置。 Content providers don't automatically transfer data, but in conjunction with other parts of Android a content provider simplifies the process of detecting when data has changed. 内容提供商不会自动传输数据,但是与Android其他部分结合使用时,内容提供商可以简化检测数据何时发生更改的过程。

To transfer data between the device and a server, you'll need to set up your server to provide database data using HTTP, learn how to connect to the HTTP server interface from Android, send requests (I suggest the REST protocol) to access the server, send REST requests to transfer data, and then store the data on the device, probably by using a content provider. 要在设备和服务器之间传输数据,您需要将服务器设置为使用HTTP提供数据库数据,了解如何从Android连接到HTTP服务器接口,发送请求(建议使用REST协议)以访问服务器,发送REST请求以传输数据,然后可能通过使用内容提供程序将数据存储在设备上。

You may also need to learn how to work with user accounts in Android, using the android.accounts.Account class. 您可能还需要使用android.accounts.Account类学习如何在Android中使用用户帐户。

Most of these topics are described in detail at the website developer.android.com, which is Google's official Android SDK documentation. 这些主题中的大多数主题都在网站developer.android.com上进行了详细描述,这是Google的官方Android SDK文档。

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

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