简体   繁体   English

从Android手机发送数据到PC?

[英]Sending a data from android phone to pc?

I am creating a "tracking system" for my android phone. 我正在为我的Android手机创建一个“跟踪系统”。 Basically, the phone would transmit it latitude/longitude to a C# program that will receive the coordinates and display it on a map. 基本上,电话会将纬度/经度传输到C#程序,该程序将接收坐标并将其显示在地图上。 I managed to get the phone's latitude/longitude coordinates but I need a way to transmit that data to my C# application running in my PC. 我设法获得了手机的纬度/经度坐标,但是我需要一种方法来将该数据传输到在PC上运行的C#应用​​程序中。 I know my way around C# and Java but never really got into network programming. 我知道我使用C#和Java的方式,但从未真正涉足网络编程。 Is there a way to do this ? 有没有办法做到这一点 ?

I'd look into C# Webservices, very powerful. 我将研究功能非常强大的C#Web服务。 The communication protocol is SOAP (Simple Object Access Protocol) which is a popular and well supported standard. 通信协议是SOAP(简单对象访问协议),它是一种流行且受到良好支持的标准。

Good starting reference: Your first C# Web Service 良好的入门参考: 您的第一个C#Web服务

I can't speak to the C# side of it, but if you write a C# server to receive post requests, the Apache HttpClient makes it relatively simple to send requests. 我不能说它的C#端,但是如果您编写一个C#服务器来接收发布请求,则Apache HttpClient使得发送请求相对简单。 There are a bunch of other questions on SO that will help with setting up the client side on your phone if you poke around a bit. SO上还有许多其他问题,如果您稍加拨动,将有助于在手机上设置客户端。

You have different way to do it. 您有不同的方式来做。

  • The first is to send data over the cloud to interact through distant server. 首先是通过云发送数据以通过远程服务器进行交互。 So the both devices have to be connected to Internet 因此,两个设备都必须连接到Internet
  • The second id to send the data over a local network so the data have to be on the same network and have to share their IPs 第二个ID,用于通过本地网络发送数据,因此数据必须位于同一网络上,并且必须共享其IP
  • The third is to use adb forward which allows to build a socket connection between the 2 devices over a USB cable. 第三种是使用adb forward ,它允许通过USB电缆在两个设备之间建立套接字连接。 The requirements are that the phone have to be on debug mode I think and that the driver are installed on the PC so the phone is recognized by ADB. 我的要求是手机必须处于调试模式,并且驱动程序已安装在PC上,以便ADB可以识别该手机。
  • I can add one more by using a Bluetooth connection. 我可以使用蓝牙连接再添加一个。 Find information here 在这里找到信息

The correct way to do it would be to build WCF service which allows many different protocols to receive data. 正确的方法是构建WCF服务,该服务允许许多不同的协议接收数据。 This would could be a very powerful solution that can be extended in future. 这将是一个非常强大的解决方案,可以在将来扩展。

The fastest and easiest IMO would be to create ASP.NET MVC application, define a POCO Model for your longitude/latitude and create an action that would take your Model as parameter. 最快和最简单的IMO将是创建ASP.NET MVC应用程序,为您的经度/纬度定义POCO模型,并创建一个将模型作为参数的操作。 Then use HttpClient and HttpPost on android to send the data. 然后在android上使用HttpClient和HttpPost发送数据。 The trick here is to name the variables in your post request same as ones you define in your C# Model. 这里的窍门是为发布请求中的变量命名,使其与您在C#模型中定义的变量相同。

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

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