12

I developing a GCM application. Everything works fine when the device is not idle (i.e. sleeping by pressing the power button). However, when I send the message when the device is idle the device does not wake up.

I have done the following:

  1. Verified that delay_while_idle is not set to true in the server app
  2. Used a different collapse key for each message
  3. Rebooted the device multiple times
  4. Tried omitting the delay_while_idle completely from the server side - it has no effect

I am targetting Android 2.2 api level 8 (lowest version), testing on an actual device running Android 2.3.6

Device is using wi-fi, there is no sim card - but receives messages fine while running and not idle.

This is the client manifest permission section:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<permission
    android:name="com.tranwall.sdk.device.android.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="basePackage.android.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"  />           
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />    
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.INTERNET" /> 

Thanks in advance for any help

Will777
  • 309
  • 3
  • 12

3 Answers3

4

problem within manifest file only.Make sure the following are the contents of manifest file GCM

<permission
    android:name="packagename.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />

<uses-permission android:name="packagename.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

<application>
    <receiver 
        android:name="com.google.android.gcm.GCMBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
            <category android:name="packagename" />
        </intent-filter>
     </receiver>
     <service android:name=".GCMIntentService" android:enabled="true" />
</application>
Tim
  • 41,901
  • 18
  • 127
  • 145
koti
  • 3,681
  • 5
  • 34
  • 58
  • Hi koti,I have the similar setup for the broadcast receiver and intent service - I only posted the permissions section of my manifest. The client app works perfectly when the device is not idle. I can see from the log that even when idle the message was received - the only issue is the fact that the incoming push message does not wake the device up – Will777 Jul 31 '12 at 09:08
  • So In idle mode also you are getting message means its calling onMessage() method of service in there you can write some wake code which is in this post http://stackoverflow.com/questions/5215367/android-how-can-i-wake-up-the-phone-from-a-hard-sleep-to-take-a-picture – koti Jul 31 '12 at 09:17
  • Thanks, I am going to try doing that - I was just under the impression that the GCM client libraries will wake the device when the message arrives – Will777 Jul 31 '12 at 09:29
  • I have implemented the wake lock mechanism as described in http://stackoverflow.com/questions/6864712/android-alarmmanager-not-waking-phone-up?rq=1 - it works. The phone will now wake up when the push message arrives. I acquired the lock in onMessage of the receiver. – Will777 Jul 31 '12 at 10:38
4

delayWhileIdle=false

delay_while_idle : If included, indicates that the message should not be sent immediately if the device is idle.
The server will wait for the device to become active, and then only the last message for each *collapse_key* value will be sent. Optional. The default value is false, and must be a JSON boolean.

Freakyuser
  • 2,774
  • 17
  • 45
  • 72
jnagjaeho
  • 41
  • 1
2

Server side need this code;

    builder.delayWhileIdle(false);

it's mean that no wake up phone on deep sleep. but received message.

then when wake up user phone, generated new intent for GCMIntentService.

seyeon
  • 4,092
  • 2
  • 15
  • 12