0

my problem is that my gcm works well and i am receiving notifications, but when the screen of my cellphone is off my GcmReceiver stop working and i do not receive notifications more

Any idea of why this is happening ? Thanks in advance!

this is my manifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="schan.main"
>
<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="17"/>
<permission android:name="schan.main.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />
<uses-permission android:name="schan.main.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:persistent="true"
    android:theme="@style/Theme.Schan"        >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <receiver
        android:name="com.google.android.gms.gcm.GcmReceiver"
        android:exported="true"
        android:permission="com.google.android.c2dm.permission.SEND">
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="schan.main" />
            <action android:name="android.intent.action.BOOT_COMPLETED"/>
        </intent-filter>
        <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
    </receiver>
    <service
        android:name="schan.main.MyGcmListenerService"
        android:exported="false">
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <action android:name="android.intent.action.BOOT_COMPLETED"/>
        </intent-filter>
    </service>
    <service
        android:name="schan.main.MyInstanceIDListenerService"
        android:exported="false">
        <intent-filter>
            <action android:name="com.google.android.gms.iid.InstanceID" />
        </intent-filter>
    </service>
    <service
        android:name="schan.main.RegistrationIntentService"
        android:exported="false">
    </service>
    <activity
        android:name=".LoginActivity"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/login"
        android:parentActivityName=".MainActivity"
        android:theme="@style/Theme.Schan" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="schan.main.MainActivity" />
    </activity>
    <activity
        android:name=".SigupActivity"
        android:label="@string/joinus"
        android:parentActivityName=".MainActivity" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="schan.main.MainActivity" />
    </activity>
    <activity
        android:name=".Alert"
        android:theme="@android:style/Theme.Translucent.NoTitleBar"
        android:label="@string/title_activity_alert_dialog" >
    </activity>
</application>

Update

i found my real problem, is this one how can i put this configuration on my huawei cellphone?

Community
  • 1
  • 1
hvar90
  • 213
  • 2
  • 9
  • @d.datul1990 no, i did not, because is necessary to change the configuration of the cellphone, there is not much information about how to change configuration programatically for huawei cellphones **note:** my problem is only for huawey cellphones **read:** https://telegram.org/faq#notification-problems – hvar90 Oct 18 '16 at 06:36
  • so possibly device specific issue? – Android Enthusiast Oct 18 '16 at 06:47
  • @d.datul1990 yes sir "Huawei and Xiaomi devices have evil task killer services that interfere with the notification service" – hvar90 Oct 18 '16 at 12:22

1 Answers1

0

First, you need 'Wakeful broadcast receiver' It help for the common pattern of implementing a BroadcastReceiver that receives a device wakeup event and then passes the work off to a Service, while ensuring that the device does not go back to sleep during the transition. This class takes care of creating and managing a partial wake lock for you; you must request the WAKE_LOCK permission to use it.

Second, you need to use 'delay_while_idle', it indicates that the messages 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. The default value is false.

Android Enthusiast
  • 4,826
  • 2
  • 15
  • 30
  • thank for your answer, at the first part you say that i need Wakeful broadcast receiver but i am using com.google.android.gms.gcm.GcmReceiver so this receiver contains Wakeful broadcast receiver and it passes the work off to schan.main.MyGcmListenerService and i am using WAKE_LOCK permission too, so maybe the problem is in com.google.android.gms.gcm.GcmReceiver but i can not modify this receiver because this is the receiver for GCM android, for the second part i tested with delay_while_idle = true and with delay_while_idle = false but it not working on both ways – hvar90 Jan 23 '16 at 22:38