2

My problem is that i need that my app is always awake to receive notification because i want to create a chat app like whatsapp, but when the app is closed the notifications do not work, i have read http://developer.android.com/intl/es/guide/components/services.html and http://developer.android.com/intl/es/guide/components/processes-and-threads.html and i thought that if i created other process with android:process attribute on GcmListenerService i could keeping alive the service but that did not work

the other way that i thought was overriding the onStartCommand method from GcmListenerService and to return START_STICKY constant

  @Override
public int onStartCommand(Intent intent, int flags, int startId) {

    return START_STICKY;
}

but the problem with this way is that GcmListenerService has the onStartCommand method with final so i can not override that method

so on android documentation there is not solution to this problem?

the only one solution that i could find is to go to setting on my cellphone and after that go to power saving ----> protected applications and to check my app to keep my app working even when my app were closed

so anyone has the solution for this problem? thanks

Edit #2

 <?xml version="1.0" encoding="utf-8"?>
<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: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" />
            </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>
</manifest>

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
  • 1
    Your `GcmReceiver` should be triggered even if the app is closed. I'm actually testing that right now, with configuration exactly as you have yours, and it's working for me. Show what your `GcmReceiver` class looks like. – Daniel Nugent Jan 22 '16 at 00:18
  • @DanielNugent thanks for your answer, on my cellphone does not work, this only work if my app is opened or if this is in background but if this is totally closed i do not receive notification – hvar90 Jan 22 '16 at 00:25
  • @DanielNugent i dont have GcmReceiver class i used the package com.google.android.gms.gcm.GcmReceiver i have GcmListenerService class – hvar90 Jan 22 '16 at 00:36
  • @DanielNugent only it works if i change the settings on my cellphone, i watch the settings for whatsapp and it has check by default configuration to work even when whatsapp were closed but my app by default is not checked – hvar90 Jan 22 '16 at 00:43
  • Can you post your entire manifest including permissions? – Daniel Nugent Jan 22 '16 at 00:47
  • @DanielNugent of course – hvar90 Jan 22 '16 at 00:48
  • Ok, your permissions look good to me. I'm not sure why it's not working for you, maybe have a look at this, it might be related: http://stackoverflow.com/questions/31178029/gcmlistenerservice-onmessagereceived-not-called – Daniel Nugent Jan 22 '16 at 01:08
  • @DanielNugent but the difference is that my app receive notifications normally but the problem is when i close my app,I do not receive more notifications, my problem might be related with this http://stackoverflow.com/questions/23333948/gcm-message-is-not-sent-when-the-app-is-not-open – hvar90 Jan 22 '16 at 01:22

1 Answers1

0

Well thats what broadcast receiver ment to do. You probably forgot or mismatched somewhere related to the receiver, but you havent provided enough code so its hard to tell.

I will also suggest you to try narrowing the issues you are facing. You cant assume that phone settings is the last solution. Android and google developed a great framework for you, so use it...

Juvi
  • 1,078
  • 1
  • 19
  • 38
  • thank you for your answer, i edited my answer and i put code from my manifest.xml my code is like the example from the android documentation, when i said about phone settings i meant that is a solution but i am looking for an android solution, sorry for the misunderstanding – hvar90 Jan 22 '16 at 00:33