在网络连接打开后接收有关Android的通知 [英] Receive notification on android after network connection is on

查看:139
本文介绍了在网络连接打开后接收有关Android的通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在网络连接关闭时将通知存储到本地存储中,并在网络启动后收到至少10个通知。



我用过cordova push plugins和android sdk。



我尝试了什么:



我是新手android developer.Please帮我

I want to store notification into local storage when network connection is off and receive atleast 10 notification after network is on .

I have used cordova push plugins and android sdk.

What I have tried:

I am new in android developer.Please help me

推荐答案

您可能要考虑使用 BroadcastReceiver 代替 ConnectivityManager.CONNECTIVITY_ACTION 。来自文档:



网络连接发生了变化。已建立或丢失连接。受影响网络的NetworkInfo是作为额外发送的;应该查看是否发生了什么类型的连接事件。



此接收器适用于WiFi和蜂窝数据连接,与PhoneStateListener.LISTEN_DATA_CONNECTION_STATE不同,

只会通知您蜂窝网络的变化。
You might want to consider using a BroadcastReceiver for ConnectivityManager.CONNECTIVITY_ACTION instead. From the docs:

A change in network connectivity has occurred. A connection has either been established or lost. The NetworkInfo for the affected network is sent as an extra; it should be consulted to see what kind of connectivity event occurred.

This receiver works for both WiFi and cellular data connectivity, unlike PhoneStateListener.LISTEN_DATA_CONNECTION_STATE,
which will only notify you for changes in cellular networks.


这篇关于在网络连接打开后接收有关Android的通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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