I am trying to use google cloud messaging service to store gcm id when user login into the system but i do not how to do it on login activity.Anybody can help me with any working sample?

有帮助吗?

解决方案

May be you can follow this link or most prefered from android developers. Here's another link with nice tutorial about implementing google Cloud messaging

其他提示

please use below function:

public static String registerClient(Activity activity) {
        String regId = "";
        String registrationStatus;
        try {
            // Check that the device supports GCM (should be in a try / catch)
            GCMRegistrar.checkDevice(activity);

            // Check the manifest to be sure this app has all the required
            // permissions.
            GCMRegistrar.checkManifest(activity);

            // Get the existing registration id, if it exists.
            regId = GCMRegistrar.getRegistrationId(activity);

            if (regId.equals("")) {

                registrationStatus = "Registering...";

                // register this device for this project
                GCMRegistrar.register(QwichesApplication.mContext,
                        CommonVariable.GCM_PROJECTID);
                regId = GCMRegistrar.getRegistrationId(activity);

                registrationStatus = "Registration Acquired";
                Log.d("tag", regId);
                // This is actually a dummy function. At this point, one
                // would send the registration id, and other identifying
                // information to your server, which should save the id
                // for use when broadcasting messages.

            } else {

                registrationStatus = "Already registered";

            }

        } catch (Exception e) {

            e.printStackTrace();
            registrationStatus = e.getMessage();

        }

        Log.d("tag", regId);

        // This is part of our CHEAT. For this demo, you'll need to
        // capture this registration id so it can be used in our demo web
        // service.

        return regId;

    }

this function returns gcm_id . i hope its useful to you...

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top