Android GoogleCloudMessaging - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android GoogleCloudMessaging class.

This code example shows how to use the following methods:register
				String msg = "";
				try { 
					if (gcm == null) {
						gcm = GoogleCloudMessaging.getInstance(context);
					} 
					regid = gcm.register(SENDER_ID);
					msg = "Device registered, registration id=" + regid;
 
					// You should send the registration ID to your server over 
					// HTTP, 
					// so it can use GCM/HTTP or CCS to send messages to your 
					// app. 
 
					// For this demo: we don't need to send it because the 
					// device 
					// will send upstream messages to a server that echo back 
					// the message 
					// using the 'from' address in the message. 
 
					// Save the regid - no need to register again. 
3
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:register
                String msg = "";
                try { 
                    if (gcm == null) {
                        gcm = GoogleCloudMessaging.getInstance(context);
                    } 
                    regid = gcm.register(SENDER_ID);
                    msg = "Device registered, registration ID=" + regid;
 
                    // You should send the registration ID to your server over HTTP, so it 
                    // can use GCM/HTTP or CCS to send messages to your app. 
                    Log.e(Constants._COUNT, "Before sending to Backend");
                    sendRegistrationIdToBackend(); 
 
                    // For this demo: we don't need to send it because the device will send 
                    // upstream messages to a server that echo back the message using the 
                    // 'from' address in the message. 
 
                    // Persist the regID - no need to register again. 
                    storeRegistrationId(context, regid);
                } catch (IOException ex) {
3
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:register
				String msg = "";
				try { 
					if (gcm == null) {
						gcm = GoogleCloudMessaging.getInstance(context);
					} 
					regid = gcm.register(SENDER_ID);
					msg = "Device registered, registration ID=" + regid;
 
					// You should send the registration ID to your server over 
					// HTTP, so it 
					// can use GCM/HTTP or CCS to send messages to your app. 
					sendRegistrationIdToBackend(); 
 
					// For this demo: we don't need to send it because the 
					// device will send 
					// upstream messages to a server that echo back the message 
					// using the 
					// 'from' address in the message. 
 
					// Persist the regID - no need to register again. 
3
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:register
	            String msg = "";
	            try { 
	                if (gcm == null) {
	                    gcm = GoogleCloudMessaging.getInstance(context);
	                } 
	                regid = gcm.register(SENDER_ID);
	                msg = "Device registered, registration id=" + regid;
 
	                // You should send the registration ID to your server over HTTP, 
	                // so it can use GCM/HTTP or CCS to send messages to your app. 
 
	                // For this demo: we don't need to send it because the device 
	                // will send upstream messages to a server that echo back the message 
	                // using the 'from' address in the message. 
 
	                // Save the regid - no need to register again. 
	                setRegistrationId(context, regid);
	            } catch (IOException ex) {
	                msg = "Error :" + ex.getMessage();
	            } 
3
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:register
                String msg = "";
                try { 
                    if (gcm == null) {
                        gcm = GoogleCloudMessaging.getInstance(context);
                    } 
                    regid = gcm.register(SENDER_ID);
                    msg = "Device registered, registration ID=" + regid;
 
                    // You should send the registration ID to your server over HTTP, so it 
                    // can use GCM/HTTP or CCS to send messages to your app. 
                    sendRegistrationIdToBackend(); 
 
                    // For this demo: we don't need to send it because the device will send 
                    // upstream messages to a server that echo back the message using the 
                    // 'from' address in the message. 
 
                    // Persist the regID - no need to register again. 
                    storeRegistrationId(context, regid);
                } catch (IOException ex) {
                    msg = "Error :" + ex.getMessage();
3
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:register
                String msg = "";
                try { 
                    if (gcm == null) {
                        gcm = GoogleCloudMessaging.getInstance(context);
                    } 
                    regid = gcm.register(SENDER_ID);
                    msg = "Device registered, registration ID=" + regid;
 
                    // You should send the registration ID to your server over HTTP, so it 
                    // can use GCM/HTTP or CCS to send messages to your app. 
                    sendRegistrationIdToBackend(); 
 
                    // For this demo: we don't need to send it because the device will send 
                    // upstream messages to a server that echo back the message using the 
                    // 'from' address in the message. 
 
                    // Persist the regID - no need to register again. 
                    storeRegistrationId(context, regid);
                } catch (IOException ex) {
                    msg = "Error :" + ex.getMessage();
3
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getMessageType
 
	@Override 
	public void onReceive(Context context, Intent intent) {
		GrapeGuice.getInjector(context).injectMembers(this);
		logger.debug("onReceive() %s", BundleUtil.toString(intent.getExtras()));
        String messageType = gcm.getMessageType(intent);
        if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
    		logger.debug("onReceive() error"); 
        	pushHandler.onError(intent.getExtras().toString());
        } 
        else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
        	logger.debug("onReceive() message deleted"); 
        } 
        else { 
        	logger.debug("onReceive() message"); 
        	pushHandler.onMessage(intent.getExtras());
        } 
        setResultCode(Activity.RESULT_OK);
	} 
} 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:register
                try { 
                    if (gcm == null) {
                        gcm = GoogleCloudMessaging.getInstance(context);
                    } 
 
                    regid = gcm.register(SENDER_ID);
                    msg = "Device registered, registration ID=" + regid;
 
                    // You should send the registration ID to your server over HTTP, so it 
                    // can use GCM/HTTP or CCS to send messages to your app. 
                    sendRegistrationIdToBackend(); 
 
                    // For this demo: we don't need to send it because the device will send 
                    // upstream messages to a server that echo back the message using the 
                    // 'from' address in the message. 
 
                    // Persist the regID - no need to register again. 
                    storeRegistrationId(context, regid);
                } catch (IOException ex) {
                    msg = "Error :" + ex.getMessage();
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:register
                try { 
                    if (gcm == null) {
                        gcm = GoogleCloudMessaging.getInstance(context);
                    } 
 
                    regid = gcm.register(sender_id);
 
                    // You should send the registration ID to your server over HTTP, so it 
                    // can use GCM/HTTP or CCS to send messages to your app. 
                    //sendRegistrationIdToBackend(); 
 
                    // Persist the regID - no need to register again. 
                    storeRegistrationId(context, regid);
                } catch (IOException ex) {
			ex.printStackTrace();
                } 
                return regid;
            } 
 
            @Override 
3
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:send
                    String msg = "";
                    try { 
                        Bundle data = new Bundle();
                        data.putString("hello", "World");
                        String id = Integer.toString(msgId.incrementAndGet());
                        gcm.send(SENDER_ID + "@gcm.googleapis.com", id, data);
                        msg = "Sent message";
                    } catch (IOException ex) {
                        msg = "Error :" + ex.getMessage();
                    } 
                    return msg;
                } 
 
                @Override 
                protected void onPostExecute(String msg) {
                    mDisplay.append(msg + "\n");
                } 
            }.execute(null, null, null);
        } else if (view == findViewById(R.id.clear)) {
            mDisplay.setText("");
4
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Android GoogleCloudMessaging Questions & Answers:

See Code Examples for Android GoogleCloudMessaging Methods: