alarmmanager

推送技术原理:移动无线网络长连接

核能气质少年 提交于 2019-12-03 18:56:43
移动互联网应用现状 因为手机平台本身、电量、网络流量的限制,移动互联网应用在设计上跟传统 PC 上的应用很大不一样,需要根据手机本身的特点,尽量的节省电量和流量,同时又要尽可能的保证数据能及时到达客户端。 为了解决数据同步的问题,在手机平台上,常用的方法有2种。一种是定时去服务器上查询数据,也叫Polling,还有一种手机跟服务器之间维护一个 TCP 长连接,当服务器有数据时,实时推送到客户端,也就是我们说的 Push。 从耗费的电量、流量和数据送达的及时性来说,Push 都会有明显的优势,但 Push 的实现和维护成本相对较高。在移动无线网络下维护长连接,相对也有一些技术上的难度。本文试图给大家介绍一下我们 极光推送 在 Android 平台上是如何维护长连接。 移动无线网络的特点 因为 IP v4 的 IP 量有限,运营商分配给手机终端的 IP 是运营商内网的 IP,手机要连接 Internet,就需要通过运营商的网关做一个网络地址转换(Network Address Translation,NAT)。简单的说运营商的网关需要维护一个外网 IP、端口到内网 IP、端口的对应关系,以确保内网的手机可以跟 Internet 的服务器通讯。 图片源自 cisco.com. NAT 功能由图中的 GGSN 模块实现。 大部分移动无线网络运营商都在链路一段时间没有数据通讯时,会淘汰

How to use Android AlarmManager with small intervals like 1 minute?

喜欢而已 提交于 2019-12-03 18:05:26
问题 I want to make some external service monitor and be notified on problems as fast as possible. I tried to set up AlarmManager with 1-2 minutes interval, but it looks like it fires randomly every several minutes. Of course, I want to be safe from killing my background task by android, which would stop monitoring if I just use Service . Is it possible to use AlarmManager in small, accurate intervals? Which approaches are used in applications like Facebook, Gmail to notify about new messages?

AlarmManager: how to schedule a daily alarm and deal with time changes

喜你入骨 提交于 2019-12-03 17:11:27
问题 I need to set up an alarm daily at a given hour. I'm programming the alarm using AlarmManager.RTC_WAKEUP , so it uses the system time as reference. I'm setting the alarm to first execute at the desired hour, then to repeat daily: alarmManager.setRepeating( AlarmManager.RTC_WAKEUP, getTimestampToday("12:00"), AlarmManager.INTERVAL_DAY, pendingIntent ); The getTimestampToday method returns a long timestamp for today at the desired hour. It does so by obtaining the local date for today, then

Scheduled Alarm Manager not working Android

岁酱吖の 提交于 2019-12-03 15:39:29
I am trying to start an alarm service that repeats every day at a particular time. I have gone through a lot of threads on stack overflow regarding this but no luck. I followed a few tutorials: http://karanbalkar.com/2013/07/tutorial-41-using-alarmmanager-and-broadcastreceiver-in-android/ and http://javatechig.com/android/repeat-alarm-example-in-android My service is never started and I do not understand why. Below is my code: My Manifest file: <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses

Notifications not received on Android

*爱你&永不变心* 提交于 2019-12-03 14:39:40
I am developing an android-application which main usage is displaying notifications at a set time (some specific calendar app). One of the main complaints is that users do not (always) receive notifications , and I am at wits end. We have internally tested the code below against Android 4.4, 6, 7.0, 7.1, 8.0, 8.1 on emulators and used about 10 real devices (6 to 8.1), and all devices received their notifications on time. Even across reboots, the notifications were all received on time. One of the things we have ran into was the SecurityException on Samsung devices (>500 registered alarms),

List of Android task killers

北战南征 提交于 2019-12-03 14:04:50
问题 I am trying to do a list of Android task killers that are installed by default on the operating system. The problem is that Android is modified by the phone's manufacturer and it is hard to keep up with what everyone is doing. So far I have found this: Smart manager - On Samsung phones. Could not call alarm manager but you can avoid this if your package name contains "alarm" or "alert" Doze - On Android 6. should not interrupt the app but it may delay alarm manager or network processes

How to check if alarm is set

老子叫甜甜 提交于 2019-12-03 13:01:50
问题 I'm trying to check if my alarm is active or not. The alarmIsSet method will return false before the alarm is set, true when the alarm is set. So far so good, however, after the alarm i canceled alarmIsSet will continue to return true until I reboot the device. How do I fix this? public class Alarm extends Activity { private Intent intent = new Intent("PROPOSE_A_TOAST"); private void alarm (boolean activate) { AlarmManager am = (AlarmManager)getSystemService(Context.ALARM_SERVICE);

DP5 7.0 - Does adding extras to a pending intent fail?

那年仲夏 提交于 2019-12-03 13:01:05
Adding the linked issue on tracker: https://code.google.com/p/android/issues/detail?id=216581&thanks=216581&ts=1468962325 So I installed the DP5 Android 7.0 release onto my Nexus 5X today. I've been working on an app that schedules local notifications at specific times using Android's AlarmManager class. Up until this release, the code has been working great on devices running KitKat, Lollipop, and Marshmallow. Below is how I'm scheduling the alarms: Intent intent = new Intent(context, AlarmManagerUtil.class); intent.setAction(AlarmManagerUtil.SET_NOTIFICATION_INTENT); intent.putExtra

How to wake up Android Wear when it is in sleep mode?

邮差的信 提交于 2019-12-03 12:46:12
When Android Wear goes to sleep mode (screen dimmed), some parts of my code are not executed. I use Timer in background service to trigger some actions, such as sending data from wear to mobile, but the data is not sent. It is sent when I tap the screen to wake it up. I also try to use Timer trigger a notification with vibration when the screen is off, but it doesn't appear until I tap the screen. In debug mode (either Bluetooth or USB), data sending and notification work fine. I suspect this is because when Android Wear is in sleep mode, its CPU works at minimum level because the Timer is

NEXT_ALARM_FORMATTED is deprecated

匿名 (未验证) 提交于 2019-12-03 09:06:55
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Since API 21 / Android 5.0 The field Settings.System.NEXT_ALARM_FORMATTED is deprecated What is the alternative for doing this? I saw http://developer.android.com/reference/android/app/AlarmManager.html#getNextAlarmClock() But I really don't know how to implement it. 回答1: You should upgrade android to api level 21 and your device also should be compatible with that, you can remove try..catch block also but it is better if in your manifest.xml android:minSdkVersion is less than 21. try { AlarmManager am = (AlarmManager)getSystemService