当没有互联网可用时如何从android向服务器发送数据 [英] how to send data to server from android when no internet is available

查看:176
本文介绍了当没有互联网可用时如何从android向服务器发送数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经制作了一个将数据发送到mysql服务器的表单应用程序.一切都很好,但是我有一个问题:如果我的应用程序没有互联网,该怎么办?如果用户有互联网,则用户输入数据并提交,但是如果我有5到10分钟没有互联网访问,该怎么办?并且用户仍然发送数据.我会丢失该数据还是有一种保存数据的方法?当再次激活互联网时,所有保存的数据都将传输到我的mysql服务器... ??

I've made a form app that send data to my mysql server. All is good but I have a question: what should I use if my app doesn't have internet..the user enters the data and is submitted if I have internet but what if for 5 or 10 minutes i don't have internet acces and the user still sends data. Do I lose that data or is there a way to save the data and when the internet is activated again all the data saved is transmited to my mysql server...??

我听说过JSON Parser,但我不知道它是如何工作的...

I've heard about JSON Parser but i don't know exactly how it works...

推荐答案

在您的android应用程序中设置BroadcastReceiver

当您的用户提交一些数据后,按提交,然后检查设备的互联网连接.如果没有互联网,则将数据存储在本地数据库或共享首选项中(如果数据很小).现在,当Internet可用时,您的广播接收器将被呼叫并检查本地数据库中的数据.如果存在,它将必须像以前一样发送该数据.

Set up a BroadcastReceiver in your android application

When your user submits some data and press submit then check for the internet connection of the device.If internet is not available then store the data in the local database or shared preferences(if data is small). Now when internet will be available,your broadcast receiver will be called and will check the data in the local database.If present ,it will have to send that data as you used to do already.

  1. 用于检查Internet连接:用于在android应用中检查互联网连接的广播接收器
  2. 用于处理数据库: Android SQLite示例
  3. 如果您希望使用sharedPreferences: 在Android中发送POST数据
  1. For checking the internet connection : How to check internet access on Android? InetAddress never times out
  2. For creating Broadcast Reciever for checking availability of network : Broadcast receiver for checking internet connection in android app
  3. For dealing with database : Android SQLite Example
  4. If you wish to use sharedPreferences : How to use SharedPreferences in Android to store, fetch and edit values
  5. For sending data to server : Sending POST data in Android

这篇关于当没有互联网可用时如何从android向服务器发送数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆