Android Push Notification GCM doesn't register device id

0 votes

Hi guys

I got a problem with the GCMRegister Library. I studied the sample project for push notifications. Now i have a problem, that i didn't got a device register id. i builded the code up like in the sample. I think the library didn't register the application, but i don't know why. 

Had anyone else the same problem? i put the code also in this topic. The main problem I got, is that deviceRegId is always empty. Maybe someone have a solution. I execute this methode in my MainActivity in a AsyncTask. 

 

public static void registerWithApp42(String projectNo) {
        App42Log.debug(" ..... Registeration Check ....");
        App42GCMService.setSenderId(projectNo);
        final String deviceRegId = GCMRegistrar.getRegistrationId(App42API.appContext);
        if (deviceRegId.equals("")) {
            // Automatically registers application on startup.
            Log.d("App Push Register", "Register task execute");
            GCMRegistrar.register(App42API.appContext, projectNo);
 
        } else  {
            App42Log.debug(" Registering on Server ....");
 
            App42API.buildPushNotificationService().storeDeviceToken(App42API.getLoggedInUser(), deviceRegId, new App42CallBack() {
 
                @Override
                public void onSuccess(Object paramObject) {
                    // TODO Auto-generated method stub
                    App42Log.debug(" ..... Registeration Success ....");
                    Log.d("App Push Register", "Registered");
                    GCMRegistrar.setRegisteredOnServer(App42API.appContext, true);
                }
 
                @Override
                public void onException(Exception paramException) {
                    App42Log.debug(" ..... Registeration Failed ....");
                    App42Log.debug("storeDeviceToken :  Exception : on start up " +paramException);
                    Log.d("App Push Register", "Register failed");
                }
            });
 
 
        }
asked Jun 6, 2014 in App42 Cloud API-BaaS by sunny.hossin (10 points)

2 Answers

0 votes
Hi Sunny, Have you followed all the steps mention in the tutorial. Kindly verify it & let me know if stuck any where. http://api.shephertz.com/tutorial/Push-Notification-Android/
answered Jun 7, 2014 by hs00105 (517 points)
edited Jun 7, 2014 by hs00105
0 votes
Hi  Sunny,

                 Please use this method. It would help you. let me know if you still face this issue.

 

/*
     * This function allows to register device for PushNotification service
     */
    public void registerNewForPushNotification(Context context, final String userID)
    {
        GCMRegistrar.checkDevice(context);
        GCMRegistrar.checkManifest(context);
        final String deviceId = GCMRegistrar.getRegistrationId(context);
        if (deviceId.equals(""))
        {
            GCMRegistrar.register(context, Constants.ProjectID);
        }
        else
        {
            final Handler callerThreadHandler = new Handler();
            new Thread()
            {
                @Override
                public void run()
                {
                    try
                    {
                        ServiceAPI sp = new ServiceAPI(Constants.App42ApiKey, Constants.App42ApiSecret);
                        String userName = userID;
                        pushService.storeDeviceToken(userName, deviceId);
                        callerThreadHandler.post(new Runnable()
                        {
                            @Override
                            public void run()
                            {

                            }
                        });
                    }
                    catch (Exception e)
                    {
                        e.printStackTrace();
                    }
                }
            }.start();
        }
    }
 This method used upon successful login or upon successful sign Up or call this method accordingly your code.

Thanks
answered Jun 9, 2014 by sarora (56 points)
Hi guys,
I created a new broadcast receiver. I used the official implementation guide from google, how you should implement a broadcast receiver while you receive pushes from a server by GCM.

http://developer.android.com/google/gcm/client.html
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...