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

查看:18
本文介绍了没有互联网时如何从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...

推荐答案

在你的安卓应用程序中设置一个 BroadcastReceiver

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

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. 用于检查互联网连接:如何在 Android 上检查互联网访问?InetAddress 永远不会超时
  2. 用于创建广播​​接收器以检查网络可用性:用于在安卓应用程序中检查互联网连接的广播接收器
  3. 用于处理数据库: Android SQLite 示例
  4. 如果您想使用 sharedPreferences : 如何在 Android 中使用 SharedPreferences 来存储、获取和编辑值
  5. 用于向服务器发送数据: 在 Android 中发送 POST 数据

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

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