Start a new topic

Push notification not working in android.

Hi,


I have been spent my five days on it. I am trying to send push notification from Business Logic. Here i am attaching logcat ouput and my manifest xml code and GCMReceiver class file. Please tell me what is issue in it..


fix my problems. kinvey not updated the push guides.


thnx


  LogCat output:

06-17 18:45:05.121: V/GCMBroadcastReceiver(25802): onReceive: com.google.android.c2dm.intent.REGISTRATION
06-17 18:45:05.121: V/GCMRegistrar(25802): Setting the name of retry receiver class to com.example.teamtaska.push.GCMReceiver
06-17 18:45:05.121: V/GCMBroadcastReceiver(25802): GCM IntentService class: com.example.teamtaska.push.GCMService
06-17 18:45:05.131: V/GCMBaseIntentService(25802): Acquiring wakelock
06-17 18:45:05.151: E/com.kinvey.android.push.AbstractPush(25802): unable to register with GCM: INVALID_PARAMETERS
06-17 18:45:05.151: W/System.err(25802): java.io.IOException: INVALID_PARAMETERS
06-17 18:45:05.161: W/System.err(25802): 	at com.google.android.gms.gcm.GoogleCloudMessaging.zza(Unknown Source)
06-17 18:45:05.161: W/System.err(25802): 	at com.google.android.gms.gcm.GoogleCloudMessaging.register(Unknown Source)
06-17 18:45:05.161: W/System.err(25802): 	at com.kinvey.android.push.GCMPush$1.doInBackground(GCMPush.java:101)
06-17 18:45:05.161: W/System.err(25802): 	at com.kinvey.android.push.GCMPush$1.doInBackground(GCMPush.java:96)
06-17 18:45:05.161: W/System.err(25802): 	at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-17 18:45:05.161: W/System.err(25802): 	at java.util.concurrent.FutureTask.run(FutureTask.java:234)
06-17 18:45:05.161: W/System.err(25802): 	at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
06-17 18:45:05.171: W/System.err(25802): 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-17 18:45:05.171: W/System.err(25802): 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-17 18:45:05.171: W/System.err(25802): 	at java.lang.Thread.run(Thread.java:841)
06-17 18:45:15.142: V/Kinvey - Client(25802): adding new instance of AppData, new collection name 

  


 Manifest file..

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.teamtaska"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="18" />
	
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
	<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
    <uses-permission android:name="android.permission.VIBRATE" />
    
    <permission android:name="com.example.teamtaska.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />
	<uses-permission android:name="com.example.teamtaska.permission.C2D_MESSAGE" />
    
    <!-- Network State Permissions -->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    
    <!-- This app has permission to register and receive data message. -->
    <uses-permission
        android:name="com.google.android.c2dm.permission.RECEIVE" />
    
    <application
        android:name="com.example.teamtaska.UserLogin"
       	android:theme="@style/ThemeSelector" 
       	android:allowBackup="true"
        android:icon="@drawable/appicon64"
        android:label="@string/app_name" >
            
        <activity
            android:name="com.example.teamtaska.LoginActivity"
            android:label="@string/title_Login"
            android:noHistory="true">
            
            </activity>
                
            <intent-filter>
                <action android:name="android.accounts.AccountAuthenticator" >
                </action>
            </intent-filter>
  
               <meta-data android:name="com.google.android.gms.version"
    			android:value="@integer/google_play_services_version" />
            
            <meta-data
                android:name="android.accounts.AccountAuthenticator"
                android:resource="@xml/authenticator" />
        
        
            <intent-filter>
                <action android:name="android.intent.action.VIEW"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="android.intent.category.BROWSABLE"/>
                <data android:scheme="http" android:host="kinvey-tutorials"/>
            </intent-filter>
            
        
        
            <activity
            android:name="com.example.teamtaska.MainActivity"
            android:label="@string/app_name"
            android:configChanges="orientation|screenSize" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        
            
        
        <activity
            android:name="com.example.teamtaska.admin.AdminHomeActivity"
            android:label="Welcome"
            android:icon="@drawable/ic_drawer48"
            android:configChanges="orientation|screenSize">
            
            <meta-data
        		android:name="android.app.searchable"
        		android:resource="@xml/searchable">
    		</meta-data>
       	</activity>
            
        <activity
            android:name="com.example.teamtaska.user.UserActivity"
            android:configChanges="orientation|screenSize">
            </activity>
        
        <!--
          BroadcastReceiver that will receive intents from GCM
          services and handle them to the custom IntentService.

          The com.google.android.c2dm.permission.SEND permission is necessary
          so only GCM services can send data messages for the app.
        -->
        
        <receiver
        android:name="com.example.teamtaska.push.GCMReceiver"
        android:exported="true"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <!-- Receives the actual messages. -->
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <!-- Receives the registration id. -->
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
            <category android:name="com.example.teamtaska" />
        </intent-filter>
    	</receiver>
    	<service android:name="com.example.teamtaska.GCMService" android:exported="false">
    	    
    	    </service>
        
    	
    </application>

</manifest>

 

GCMService:

 

package com.example.teamtaska.push;

import android.app.NotificationManager;
import android.content.Context;
import android.support.v4.app.NotificationCompat;
import android.util.Log;

import com.example.teamtaska.R;
import com.kinvey.android.push.KinveyGCMService;


public class GCMService extends KinveyGCMService {
    @Override
    public void onMessage(String message) {
    	Log.i("PUSH", "MESSAGE RECIEVED!");
    	
        displayNotification(message);
    }
    @Override
    public void onError(String error) {
        displayNotification(error);
    }
    @Override
    public void onDelete(String deleted) {
        displayNotification(deleted);
    }
    @Override
    public void onRegistered(String gcmID) {
    	Log.i("TEST", "GCM - onRegister, new gcmID is: " + gcmID); 
        displayNotification(gcmID);
    }
    @Override
    public void onUnregistered(String oldID) {
    	
    	Log.i("TEST", "GCM- onUnregistered. old id is: " + oldID);
        displayNotification(oldID);
    }
    //This method will return the WakefulBroadcastReceiver class you define in the next step
    public Class getReceiver() {
        return GCMReceiver.class;
    }
    private void displayNotification(String message){
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle(getApplicationContext().getResources().getString(R.string.app_name))
            .setContentText(message);
        NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(1, mBuilder.build());
    }
}

 

package com.example.teamtaska.push;

import android.app.NotificationManager;
import android.content.Context;
import android.support.v4.app.NotificationCompat;
import android.util.Log;

import com.example.teamtaska.R;
import com.kinvey.android.push.KinveyGCMService;


public class GCMService extends KinveyGCMService {
    @Override
    public void onMessage(String message) {
    	Log.i("PUSH", "MESSAGE RECIEVED!");
    	
        displayNotification(message);
    }
    @Override
    public void onError(String error) {
        displayNotification(error);
    }
    @Override
    public void onDelete(String deleted) {
        displayNotification(deleted);
    }
    @Override
    public void onRegistered(String gcmID) {
    	Log.i("TEST", "GCM - onRegister, new gcmID is: " + gcmID); 
        displayNotification(gcmID);
    }
    @Override
    public void onUnregistered(String oldID) {
    	
    	Log.i("TEST", "GCM- onUnregistered. old id is: " + oldID);
        displayNotification(oldID);
    }
    //This method will return the WakefulBroadcastReceiver class you define in the next step
    public Class getReceiver() {
        return GCMReceiver.class;
    }
    private void displayNotification(String message){
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle(getApplicationContext().getResources().getString(R.string.app_name))
            .setContentText(message);
        NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(1, mBuilder.build());
    }
}

  

GCMReceiver:


 

package com.example.teamtaska.push;

import com.example.teamtaska.R.string;
import com.google.android.gcm.GCMBroadcastReceiver;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.support.v4.content.WakefulBroadcastReceiver;

public class GCMReceiver extends GCMBroadcastReceiver {
	
	    @Override
	    public String getGCMIntentServiceClassName(Context context){
	        return GCMService.class.getName();
	    }
	
	/*
	@Override
    public void onReceive(Context context, Intent intent) {
        ComponentName comp = new ComponentName(context.getPackageName(), com.example.teamtaska.push.GCMService.class.getName());
        startWakefulService(context, (intent.setComponent(comp)));
        setResultCode(Activity.RESULT_OK);
        
    } 
    */
}

 


Thnx for inform.. but what should i do.. i want to send push on my registered applications.


1 person likes this

i have the same problem i followed the documentation and then got stuck 

Good evening Sukhpal, 


We do not do code reviews as part of our support agreement.  I apologize that you are having difficulties implementing push, we are currently in the process of simplifying the process of implementing push while simultaneously improving our documentation.


Please let me know if you have any additional questions.



Login or Signup to post a comment