List of usage examples for android.os Bundle toString
@Override public synchronized String toString()
From source file:com.getpillion.gcm.GcmIntentService.java
@Override protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras(); GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); // The getMessageType() intent parameter must be the intent you received // in your BroadcastReceiver. String messageType = gcm.getMessageType(intent); if (!extras.isEmpty()) { // has effect of unparcelling Bundle /*// w w w .j a va2s . c o m * Filter messages based on message type. Since it is likely that GCM will be * extended in the future with new message types, just ignore any message types you're * not interested in, or that you don't recognize. */ if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { //sendNotification("Send error: " + extras.toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { //sendNotification("Deleted messages on server: " + extras.toString()); // If it's a regular GCM message, do some work. } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { // This loop represents the service doing some work. /*for (int i = 0; i < 5; i++) { Log.i(TAG, "Working... " + (i + 1) + "/5 @ " + SystemClock.elapsedRealtime()); try { Thread.sleep(5000); } catch (InterruptedException e) { } } Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());*/ Log.d("GcmIntentService", "Got data from upstream " + extras.toString()); if (Konotor.getInstance(getApplicationContext()).isKonotorMessage(intent)) { Log.d("Konotor", "Got konotor message"); Konotor.getInstance(getApplicationContext()).handleGcmOnMessage(intent); return; } String simpleClassName = extras.getString("model_name"); String json = extras.getString("json"); Log.d("GcmIntentService", "json received for update - " + json + " for " + simpleClassName); Gson gson = new Gson(); Intent targetIntent = null; String msg = null; SharedPreferences sharedPref = getApplicationContext().getSharedPreferences(Constant.PREFS_NAME, 0); if (simpleClassName.equals("Ride")) { //check if ride timing or vehicle info got updated try { Ride updatedRide = gson.fromJson(json, Ride.class); Ride ride = Ride.find(Ride.class, "global_id = ?", String.valueOf(updatedRide.globalId)) .get(0); Ride.updateFromUpstream(updatedRide); targetIntent = new Intent(this, RideInfoActivity.class); targetIntent.putExtra("rideId", ride.getId()); msg = "Ride creator has updated the ride"; } catch (Exception e) { e.printStackTrace(); } } if (simpleClassName.equals("User")) { User.updateFromUpstream(gson.fromJson(json, User.class)); //lets not send notification for user info update } if (simpleClassName.equals("RideUserMapping")) { //this is important RideUserMapping rideUserMapping = gson.fromJson(json, RideUserMapping.class); //we need the ride Ride ride = Ride.find(Ride.class, "global_id = ?", String.valueOf(rideUserMapping.rideId)) .get(0); targetIntent = new Intent(this, RideInfoActivity.class); targetIntent.putExtra("rideId", ride.getId()); RideUserMapping myEntry = RideUserMapping .find(RideUserMapping.class, "ride_id = ? AND user_id = ?", String.valueOf(ride.getId()), String.valueOf(sharedPref.getLong("userId", 0L))) .get(0); RideUserMapping updated = RideUserMapping.updateFromUpstream(ride, rideUserMapping); //broadcast only for ride requester. The flow will not go into the subsequent if because of the user's status if (updated.userId == sharedPref.getLong("userId", 0L)) { switch (updated.status) { case Constant.ACCEPTED: //show to requester msg = "Your ride request is approved"; break; case Constant.REJECTED: //show to the requester - request rejected msg = "Sorry, your request has been rejected"; break; } } //broadcast for everyone if (myEntry.status != Constant.REQUESTED && myEntry.status != Constant.REJECTED && myEntry.status != Constant.CANCELLED) { switch (updated.status) { case Constant.REQUESTED: //show only to owner if (myEntry.isOwner) msg = "New ride request"; break; case Constant.CANCELLED: if (updated.isOwner) { msg = "Owner has cancelled the ride"; //for other active users } else { msg = "One traveller backed out"; //for owner } break; case Constant.CHECKED_IN: //show to all - {traveller} has reached his start point msg = "One traveller has reached his pickup point"; break; case Constant.STARTED: //show to all - ride has been started msg = "Ride has started."; break; } } } if (simpleClassName.equals("WorkHistory")) { //lets just leave this } Log.d("GcmIntentService", "message to the user - " + msg); if (msg != null) sendNotification(targetIntent, msg); Log.i(TAG, "Received: " + extras.toString()); } } // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); }
From source file:com.example.administrator.e_pic.GcmIntentService.java
@Override protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras(); String from = extras.getString(TAG_RECEIVED_FROM); int notType = Integer.parseInt(extras.getString(TAG_NOTIFICATION_TYPE)); GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); // The getMessageType() intent parameter must be the intent you received // in your BroadcastReceiver. String messageType = gcm.getMessageType(intent); if (!extras.isEmpty()) { // has effect of unparcelling Bundle /*/*from w w w. j a v a 2 s . co m*/ * Filter messages based on message type. Since it is likely that GCM will be * extended in the future with new message types, just ignore any message types you're * not interested in, or that you don't recognize. */ if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { //sendNotification("Send error: " + extras.toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { //sendNotification("Deleted messages on server: " + extras.toString()); // If it's a regular GCM message, do some work. } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { // This loop represents the service doing some work. /*for (int i = 0; i < 5; i++) { Log.i(TAG, "Working... " + (i + 1) + "/5 @ " + SystemClock.elapsedRealtime()); try { Thread.sleep(5000); } catch (InterruptedException e) { } }*/ Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime()); // Post notification of received message. sendNotification(from, notType); Log.i(TAG, "Received: " + extras.toString()); } } // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); }
From source file:lesrooster.nl.lesrooster.GcmIntentService.java
@Override protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras(); GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); // The getMessageType() intent parameter must be the intent you received // in your BroadcastReceiver. String messageType = gcm.getMessageType(intent); if (!extras.isEmpty()) { // has effect of unparcelling Bundle /*// w w w . j ava 2 s .com * Filter messages based on message type. Since it is likely that GCM will be * extended in the future with new message types, just ignore any message types you're * not interested in, or that you don't recognize. */ /*if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { sendNotification("Send error: " + extras.toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { sendNotification("Deleted messages on server: " + extras.toString()); }*/ // If it's a regular GCM message, do some work. if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { // Post notification of received message. if (extras.containsKey("m")) { String message = extras.getString("m"); message = message.substring(2, message.length() - 2); sendNotification(message, 0); } else { for (int i = 0; extras.containsKey("rw" + i); i++) { String message = extras.getString("rw" + i); //Log.i(TAG, "test"); message = message.substring(2); message = message.substring(0, message.length() - 2); Log.i(TAG, "Nummer" + i + ": " + message); sendNotification(message, i); } } Log.i(TAG, "Received: " + extras.toString()); } } // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); }
From source file:com.whereismyfriend.GcmIntentService.java
@Override protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras(); GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); // The getMessageType() intent parameter must be the intent you received // in your BroadcastReceiver. String messageType = gcm.getMessageType(intent); if (!extras.isEmpty()) { // has effect of unparcelling Bundle /*//from w w w .j av a 2 s . c o m * Filter messages based on message type. Since it is likely that GCM will be * extended in the future with new message types, just ignore any message types you're * not interested in, or that you don't recognize. */ if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { // Post notification of received message. //Si la app esta corriendo boolean corriendo = false; if (Amigos.activ != null && Amigos.isfront == 1) corriendo = true; if (Solicitudes.activ != null && Solicitudes.isfront == 1) corriendo = true; if (Mapa.activ != null && Mapa.isfront == 1) corriendo = true; if (extras.getString("alert") != null) { SharedPreferences pref = getSharedPreferences("prefs", Context.MODE_PRIVATE); boolean logueado = pref.getBoolean("log_in", false); String type = extras.getString("type"); if (!corriendo || !logueado) sendNotification(extras.getString("alert"), extras.getString("badge"), type); else { synchronized (this) { startActivity(new Intent(this, DialogPush.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) .putExtra("alert", extras.getString("alert")) .putExtra("badge", extras.getString("badge")).putExtra("type", type)); } } } Log.i(TAG, "Received: " + extras.toString()); } } // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); }
From source file:com.example.product.GcmIntentService.java
@Override protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras(); GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); // The getMessageType() intent parameter must be the intent you received // in your BroadcastReceiver. String messageType = gcm.getMessageType(intent); if (!extras.isEmpty()) { // has effect of unparcelling Bundle /*/*from w w w . j ava2 s . com*/ * Filter messages based on message type. Since it is likely that GCM will be * extended in the future with new message types, just ignore any message types you're * not interested in, or that you don't recognize. */ if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { Log.e(TAG, "GCM_MESSAGE_TYPE_SEND_ERROR"); //do nothing //sendNotification("Send error: " + extras.toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { Log.e(TAG, "GCM_MESSAGE_TYPE_DELETED"); //do nothing //sendNotification("Deleted messages on server: " + extras.toString()); // If it's a regular GCM message, do some work. } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { //? ?? Notification? . // This loop represents the service doing some work. /* for (int i = 0; i < 5; i++) { Log.i(TAG, "Working... " + (i + 1) + "/5 @ " + SystemClock.elapsedRealtime()); try { Thread.sleep(5000); } catch (InterruptedException e) { } } */ Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime()); // Post notification of received message. //sendNotification("Received: " + extras.toString()); //test sendNotification sendNotification(extras); Log.i(TAG, "Received: " + extras.toString()); //?? if (!isScreenOn(this)) { Log.i(TAG, "screen is off"); //test Intent popupIntent = new Intent(this, ActivityPopUp.class).putExtras(extras) .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // . this.startActivity(popupIntent); } //?? else { ActivityManager am = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> runList = am.getRunningTasks(10); ComponentName name = runList.get(0).topActivity; String className = name.getClassName(); boolean isAppRunning = false; Log.i(TAG, "className ==" + className); //? ?? AcitivityPopUp ? if (className.equals("com.example.product.ActivityPopUp")) { isAppRunning = true; } //?? ? if (isAppRunning == true) { Log.i(TAG, "screen is off, but popup is on"); //test Intent popupIntent = new Intent(this, ActivityPopUp.class).putExtras(extras) .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // . this.startActivity(popupIntent); // ? ? ? } //? ? ? else { // ? ? ? ? } } } } // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); }
From source file:com.cygnus.honda.GcmIntentService.java
@Override protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras(); GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); prefs = getSharedPreferences(LoginActivity.MY_PREFS_NAME, MODE_PRIVATE); editor = getSharedPreferences(LoginActivity.MY_PREFS_NAME, MODE_PRIVATE).edit(); // The getMessageType() intent parameter must be the intent you received // in your BroadcastReceiver. String messageType = gcm.getMessageType(intent); Log.i("Notification received", "Thanks"); if (!extras.isEmpty()) { // has effect of unparcelling Bundle // Post notification of received message. // sendNotification("Received: " + extras.toString()); String[] separated = extras.getString("message").split(":"); if (separated[0].equals("0")) { if (separated.length == 3) { editor.putString("refreshcontact" + separated[1], separated[1]); editor.commit();/* w w w.ja v a2s . c om*/ sendNotification(separated[2]); } else { editor.putString("refreshcontact" + separated[1], separated[1]); editor.commit(); sendNotification(separated[2] + " : " + separated[3]); } Intent intent1 = new Intent(); intent1.putExtra("message_received", extras.getString("message")); intent1.setAction("com.cygnus.honda.blinkled"); sendBroadcast(intent1); } else if (separated[0].equals("2")) { // sendNotification(extras.getString("message")); LoginActivity.checkNotifyCountReceive = true; Intent intent1 = new Intent(); intent1.putExtra("message_received", extras.getString("message")); intent1.setAction("com.cygnus.honda.blinkledcontact"); sendBroadcast(intent1); if (separated.length == 3) { sendNotification(separated[2]); } } else { sendNotification(extras.getString("message")); } LoginActivity.checkNotifyCountReceive = true; Log.i(TAG, "Received: " + extras.toString()); } // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); }
From source file:fr.RivaMedia.alertes.GcmIntentService.java
@Override protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras(); GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); // The getMessageType() intent parameter must be the intent you received // in your BroadcastReceiver. String messageType = gcm.getMessageType(intent); if (!extras.isEmpty()) { // has effect of unparcelling Bundle /*/*from w ww .j a v a 2s . c o m*/ * Filter messages based on message type. Since it is likely that GCM will be * extended in the future with new message types, just ignore any message types you're * not interested in, or that you don't recognize. */ if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { //sendNotification("Send error: " + extras.toString(),""); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { //sendNotification("Deleted messages on server: " + extras.toString(),""); // If it's a regular GCM message, do some work. } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { // This loop represents the service doing some work. /* for (int i = 0; i < 5; i++) { Log.i(TAG, "Working... " + (i + 1) + "/5 @ " + SystemClock.elapsedRealtime()); try { Thread.sleep(5000); } catch (InterruptedException e) { } } Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime()); */ String message = extras.getString("message"); String annonces = extras.getString("annonces"); AlertesManager alertManager = new AlertesManager(getApplicationContext()); try { JSONArray arrayAnnonces = new JSONArray(annonces); for (int i = 0; i < arrayAnnonces.length(); ++i) { JSONObject objectAnnonce = arrayAnnonces.getJSONObject(i); String type = objectAnnonce.getString("type"); String id = objectAnnonce.getString("id"); alertManager.ajouter(id, type); } } catch (Exception e) { } Log.i(TAG, "Received: " + extras.toString()); Log.e(TAG, "ReceivedMessage: " + message.toString()); Log.e(TAG, "ReceivedAnnonces: " + annonces.toString()); // Post notification of received message. sendNotification(message, "Cliquez ici pour les consulter"); } } // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); }
From source file:sg.lt.obs.common.gcm.GcmIntentService.java
@Override protected void onHandleIntent(Intent intent) { try {/*from www . ja v a 2 s. c o m*/ Bundle extras = intent.getExtras(); mBookingVehicleItemId = extras.getString(ObsConst.KEY_BOOKING_VEHICLE_ITEM_ID); mNotificationContent = extras.getString("title"); GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); // The getMessageType() intent parameter must be the intent you received in your BroadcastReceiver. String messageType = gcm.getMessageType(intent); Boolean isRun = false; // ActivityManager activityManager = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE); // String packageName = this.getPackageName(); // List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses(); // if (appProcesses != null) { // for (RunningAppProcessInfo appProcess : appProcesses) { // // The name of the process that this object is associated with. // if (appProcess.processName.equals(packageName) && appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) { // isRun = true; // break; // } // } // } if (ActivityStack.getAcitveActivity() != null) { isRun = true; } if (!extras.isEmpty()) { // has effect of unparcelling Bundle //Bundle[{from=1083654704210, title=30/06/2014 20:25 From Changi Airport Singapore Singapore to Boon Keng Road Singapore, mBookingVehicleItemId=8a3080d5457d005a01457f1aeec31aa4, android.support.content.wakelockid=1, collapse_key=do_not_collapse}] if (StringUtil.isNotEmpty(mBookingVehicleItemId)) { // if (isRun && GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { // mHandler.obtainMessage(0).sendToTarget(); // } else { /* * Filter messages based on message type. Since it is likely that GCM will be * extended in the future with new message types, just ignore any message types you're * not interested in, or that you don't recognize. */ if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { sendNotification("Send error: " + extras.toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { sendNotification("Deleted messages on server: " + extras.toString()); // If it's a regular GCM message, do some work. } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { // Post mNotificationContent of received message. sendNotification(extras.toString()); Log.i(TAG, "Received: " + extras.toString()); } // } } } // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.kalianey.oxapp.service.GcmBroadcastReceiver.java
@Override public void onReceive(Context context, Intent intent) { Bundle extras = intent.getExtras(); GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context); String messageType = gcm.getMessageType(intent); Log.d("Notif received", messageType.toString()); if (!extras.isEmpty()) { // has effect of unparcelling Bundle /*//w w w .ja va 2 s . co m * Filter messages based on message type. Since it is likely that GCM * will be extended in the future with new message types, just ignore * any message types you're not interested in, or that you don't * recognize. */ if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { // Is this our message?? Better be if you're going to act on it! if (MainActivity.PROJECT_NUMBER.equals(extras.getString(EXTRA_SENDER))) { // Process message and then post a notification of the received message. String type = extras.getString(EXTRA_TYPE); String message = extras.getString(EXTRA_MESSAGE); String dataString = extras.getString("extra"); //Build a conv to send to MessageView ModelConversation conversation = new ModelConversation(); try { JSONObject dataObj = new JSONObject(dataString); //{"senderId":3,"conversationId":2,"displayName":"Veda","recipientId":"1","message":"test again"} conversation.setId(dataObj.getString("conversationId")); conversation.setName(dataObj.getString("displayName")); conversation.setPreviewText(message); conversation.setOpponentId(dataObj.getString("senderId")); conversation.setInitiatorId(dataObj.getString("recipientId")); } catch (JSONException e) { e.printStackTrace(); } //Send notification String alert = "New message: " + message; sendNotification(context, alert); //Send to MessageFragment Intent broadcastIntent = new Intent(); Bundle mBundle = new Bundle(); mBundle.putSerializable("convObj", conversation); broadcastIntent.setAction("GCM_RECEIVED_ACTION"); broadcastIntent.putExtra("conversation", mBundle); broadcastIntent.putExtra("gcm", message); context.sendBroadcast(broadcastIntent); } Log.i(LOG_TAG, "Received: " + extras.toString()); } } }