Laravel 和 Android 之间如何通信?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41605710/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to communicate between Laravel and Android?
提问by Fercho Jerez
I want to understand the communication between a web application written in Laravel and an Android one. I would like to know how should I structure the folders since they will have different functionalities for the web platform and for the mobile. Thanks in advance.
我想了解用 Laravel 编写的 Web 应用程序和 Android 应用程序之间的通信。我想知道我应该如何构建文件夹,因为它们对于 Web 平台和移动设备具有不同的功能。提前致谢。
回答by Jaymin Panchal
To communicate across different platform you can use JSON
to pass the data and read that data.
要跨不同平台进行通信,您可以使用JSON
传递数据并读取该数据。
In Laravel
just create the API
which returns JSON
data and access that API
in Android
using AsyncTask
, Volley
, HttpUrlConnection
, OkHttp
.
在Laravel
刚刚创建的API
返回JSON
数据,并访问API
在Android
使用AsyncTask
,Volley
,HttpUrlConnection
,OkHttp
。
Just search on the internet you will find lots of resources.
只要在互联网上搜索,您就会发现很多资源。
Check this linkto create API
in Laravel
.
检查此链接以API
在Laravel
.
回答by akuthedeveloper
Firstly, write the Web API using the Lavarel to enhance communication between the android app and the web application. Ensure you test the json file using Postman to check if it returns valid json parameters. Then use either Retrofit, Volley in Android to communicate with the android application to parse JSON objects to enable access to information at real time...
首先,使用 Lavarel 编写 Web API 以增强 android 应用程序和 Web 应用程序之间的通信。确保您使用 Postman 测试 json 文件以检查它是否返回有效的 json 参数。然后使用 Android 中的 Retrofit、Volley 与 android 应用程序通信以解析 JSON 对象以启用实时访问信息......
回答by Mayank Pandeyz
You have to create WEB API
to achieve this.
你必须创造WEB API
才能实现这一点。
What is an API?
什么是 API?
In this sense an API - which stands for Application Programming Interface - allows for publicly exposed methods of an application to be accessed and manipulated outside of the program itself. A common usage of an API is when you wish to obtain data from an application without having to actually visit the application itself. To allow this action to take place, the application has published an API that specifically allows for foreign applications to make calls to its data and return said data to the user from inside of the external application.
从这个意义上说,API(代表应用程序编程接口)允许在程序本身之外访问和操作应用程序的公开公开方法。API 的一个常见用途是当您希望从应用程序获取数据而不必实际访问应用程序本身时。为了允许此操作发生,应用程序发布了一个 API,专门允许外部应用程序调用其数据并将所述数据从外部应用程序内部返回给用户。