不能立即连接到服务器时,Android设备上的睡眠,即使我的应用程序得到PARTIAL_WAKE_LOCK在电源管理(索尼Xperia) [英] Cannot immediately connect to the server when android device is on sleep even though my app gets the PARTIAL_WAKE_LOCK at PowerManager (Sony Xperia)

查看:1136
本文介绍了不能立即连接到服务器时,Android设备上的睡眠,即使我的应用程序得到PARTIAL_WAKE_LOCK在电源管理(索尼Xperia)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[我的Andr​​oid应用摘要]
我的应用程序监视在固定时间间隔(30秒)的服务器。

[Abstract of my android app] My app monitors the server at fixed intervals (30 seconds).

结果(发行)]


  1. 18 [H] 00 [M] 00 [S]服务器检查确定。

  2. 18 [H] 00 [M] 30 [S]服务器检查
    好。

  3. 18 [H] 03 [M] 14 [S]服务器检查确定。 < =这是问题。我的应用程序
    应在18时01分00秒检查服务器。

  1. 18[h] 00[m] 00[s] server check ok.
  2. 18[h] 00[m] 30[s] server check ok.
  3. 18[h] 03[m] 14[s] server check ok. <= This is issue. My app should check the server at 18:01:00.

我的应用程序不能在索尼XPERIA固定的时间间隔连接服务器。

My app cannot connect the server at fixed intervals at Sony xperia.

[预期结果]


  1. 18 [H] 00 [M] 00 [S]服务器检查正常。

  2. 18 [H] 00 [M] 30 [S]服务器检查正常。

  3. 18 [H] 01 [M] 00 [S]服务器检查正常。

  1. 18[h] 00[m] 00[s] server check ok.
  2. 18[h] 00[m] 30[s] server check ok.
  3. 18[h] 01[m] 00[s] server check ok.

[关于我的程序]
我的应用从临危在AlarmManager固定的时间间隔广播。
广播接收器启动服务。
在服务,我的应用程序连接到服务器。
我的应用程序的细节如下。

[About my program] My app recieves the Broadcast from AlarmManager at fixed intervals. BroadcastReceiver starts service. At service, my app connects to the server. The details of my app is below.

[第一步]:由AlarmManager setRepeating

[Step1] : setRepeating by AlarmManager

private void setRepeating () {
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
          am.setRepeating(AlarmManager.RTC_WAKEUP,System.currentTimeMillis(),pollingIntervalmsec, pendingIntent);
}

[步骤2]:从AlarmManager收到广播并启动服务

[Step2] : Recieve Broadcast from AlarmManager and start Service

 public class PollingAlarmBroadcastReceiver extends BroadcastReceiver {
        private static final String WAKELOCK_TAG = "xxx.xxx.xxx.xxx.PollingAlarmBroadcastReceiver";
        private static PowerManager.WakeLock wl;
        @Override
        public void onReceive(Context context, Intent arg1) {
            PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
            wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKELOCK_TAG);
            wl.acquire();
            Intent intent = new Intent(context, MonitoringService.class);
            context.startService(intent);
        }

        private void doOperation(Context context) {
            PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
            wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKELOCK_TAG);
            wl.acquire();
            Intent intent = new Intent(context, MonitoringService.class);
            context.startService(intent);
         }
     }

AndroidManifest.xml中

AndroidManifest.xml

    <receiver
        android:name="xxx.xxx.xxx.xxx.PollingAlarmBroadcastReceiver"
        android:exported="false">
        <intent-filter>
            <action android:name="cxxx.xxx.xxx.xxx.PollingAlarm" />
        </intent-filter>
    </receiver>

[第三步]:在服务,连接到服务器

[Step3] : At service, connect to the server.

HttpGet request = new HttpGet(url);
request.setHeaders(headers);
HttpParams params = new BasicHttpParams();
DefaultHttpClient httpClient = new DefaultHttpClient(params);
HttpResponse response = httpClient.execute(request);

【第四步】:连接服务器后释放唤醒锁

[Step4] : release wakeup lock after connecting the server.

wl.release();

[问题日志]
我的应用从AlarmManager成功接收braodcast和我的服务成功启动了。
但是我的程序在httpClient.execute暂停与下面的日志约2分钟。

[Issue log] My app successfully receives the braodcast from AlarmManager and my service successfully starts too. But my program suspends at "httpClient.execute" for about 2 minutes with the logs below.

I / QCNEA(10674):| NIMS |的getaddrinfo:主机名google.co.jp servname
  NULL数字4 APPNAME I / QCNEJ(686)|核心|
  CNE_NOTIFY_NSRM_BLOCKED_UID收到

I/QCNEA(10674): |NIMS| getaddrinfo: hostname google.co.jp servname NULL numeric 4 appname I/QCNEJ(686): |CORE| CNE_NOTIFY_NSRM_BLOCKED_UID received

[普通日志]

I / QCNEA(10674):| NIMS |的getaddrinfo:主机名google.co.jp servname
  NULL数字4 APPNAME I / QCNEA(10674):| NIMS |的getaddrinfo:主机名
  google.co.jp servname NULL数字0 APPNAME I / QCNEA(278)| NIMS |
  的getaddrinfo:主机名google.co.jp servname NULL数字0 APPNAME
  I / QCNEA(10674):| NIMS |的getaddrinfo:主机173.194.126.151 servname
  NULL数字4 APPNAME I / QCNEA(10674):| NIMS |连接:43 SADDR
  00000000000000000000000000000000:52017(28)10 DADDR
  0000000000000000ffff00007681007d:80

I/QCNEA(10674): |NIMS| getaddrinfo: hostname google.co.jp servname NULL numeric 4 appname I/QCNEA(10674): |NIMS| getaddrinfo: hostname google.co.jp servname NULL numeric 0 appname I/QCNEA(278): |NIMS| getaddrinfo: hostname google.co.jp servname NULL numeric 0 appname I/QCNEA(10674): |NIMS| getaddrinfo: hostname 173.194.126.151 servname NULL numeric 4 appname I/QCNEA(10674): |NIMS| connect: for 43 saddr 00000000000000000000000000000000:52017 (28) daddr 10 0000000000000000ffff00007681007d:80

[环境]
索尼Xperia SOL22,这是索尼Xperia Z的日本模式
Android的4.2.2。网络环境只是移动互联网(LTE)。 wifi开关是关闭的。

[Environment] Sony xperia SOL22, this is japanese model of Sony Xperia Z. Android 4.2.2. Network environment is mobile internet(LTE) only. Wifi switch is off.

[问题分析]
当我的XPERIA设备不睡我的应用程序工作正常。
我只用wifi我的应用程序也能正常工作。
我在Nexus7尝试这个程序了。它工作正常。
我的XPERIA网络设备或软件可能会继续工作,即使我的应用程序从电源管理器获得激活锁定睡觉。

[Issue analysis] My app works fine when my xperia device does not sleep. My app also works fine when I use Wifi only. I tried this app at Nexus7 too. It works fine. My xperia network device or software may continues to sleep even though my app acquires WakeLock from PowerManager.

[问题]
如何解决这个问题?任何想法是非常欢迎的。

[Question] How to fix this issue? Any ideas are very welcome.

推荐答案

我不知道开发手机应用什么,但我拥有的Xperia Z.当手机处于睡眠,经常切换Wifi和放大器;移动互联网 - 它回来时,屏幕切换上

I don't know anything about developing phone apps but I own an Xperia Z. When the phone is on sleep, it often switches of the Wifi & Mobile Internet - which comes back on when the screen is switched on.

难道这是你的问题?

这篇关于不能立即连接到服务器时,Android设备上的睡眠,即使我的应用程序得到PARTIAL_WAKE_LOCK在电源管理(索尼Xperia)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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