@Override
  protected void onHandleIntent(Intent intent) {
    // TODO Auto-generated method stub
    Bundle extras = intent.getExtras();
    String msg = intent.getStringExtra("message");
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty()) {

      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(500);
          } catch (InterruptedException e) {
          }
        }
        Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());
        // Post notification of received message.
        // sendNotification("Received: " + extras.toString());
        sendNotification(msg);
        Log.i(TAG, "Received: " + extras.toString());
      }
    }
    GcmBroadcastReciever.completeWakefulIntent(intent);
  }
Beispiel #2
0
  @Override
  protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();

    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
      /*
       * 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.
        String time = intent.getStringExtra("time");
        sendNotification("Received: " + extras.toString());
      }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
  }
  @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
      /*
       * 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)) {
      } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
        // If it's a regular GCM message, do some work.
      } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
        System.out.println(extras.toString());
        // Game Logic
        // if we are on the correct page with correct opponent, update UI
        Intent responseIntent = new Intent("com.jajmu.GOT_PUSH");
        responseIntent.putExtras(extras);
        sendOrderedBroadcast(responseIntent, null);
        // otherwise send notification
        //                sendNotification(extras);
        //    			int duration = Toast.LENGTH_SHORT;
        //				Toast toast = Toast.makeText(getApplicationContext(), extras.toString(), duration);
        //				toast.show();
      }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
  }
  @Override
  protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);

    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty()) {
      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());
      } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {

        for (int i = 0; i < 3; i++) {
          Log.i(TAG, "Working... " + (i + 1) + "/5 @ " + SystemClock.elapsedRealtime());
          try {
            Thread.sleep(5000);
          } catch (InterruptedException e) {
          }
        }
        Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());

        sendNotification(
            "Message Received from Google GCM Server: " + extras.get(Config.MESSAGE_KEY));
        Log.i(TAG, "Received: " + extras.toString());
      }
    }
    GcmBroadcastReceiver.completeWakefulIntent(intent);
  }
  @Override
  protected void onHandleIntent(Intent intent) {
    extras = intent.getExtras();
    String value = extras.getString("message");
    Log.i(TAG, "Bundle 'message' Value = " + value);

    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
    // The getMessageType() intent parameter must be the intent you received
    // in your BroadcastReceiver.
    String messageType = gcm.getMessageType(intent);

    Log.i(TAG, "in gcm intent Message = " + messageType);
    Log.i(TAG, "in gcm intent Message Bundle = " + extras.toString());

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
      /*
       * 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)) {

        // String received_message=intent.getStringExtra("text_message");

        String received_message = extras.getString("message");
        Log.i(TAG, "received_message = " + received_message);

        if (received_message.equalsIgnoreCase("track")) {
          Log.i(TAG, "In if block, received_message = " + received_message);

          Intent i = new Intent(this, DemoLocation.class);
          i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          i.putExtra("received_message", received_message);
          startActivity(i);
        }

        sendNotification("MESSAGE RECEIVED :" + received_message);

        Intent sendIntent = new Intent("message_recieved");
        sendIntent.putExtra("message", received_message);
        LocalBroadcastManager.getInstance(this).sendBroadcast(sendIntent);
      }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
  }
  @Override
  protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);

    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty()) {
      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());
      } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
        sendNotification("Message Received from Google GCM Server:\n\n" + extras.get("message"));
      }
    }
    GcmBroadcastReceiver.completeWakefulIntent(intent);
  }
  @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
      /*
       * 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.
        String mensaje = extras.getString("message");
        String enlace = extras.getString("link");
        String titulo = extras.getString("title");
        String imagen = extras.getString("image");
        sendNotification(mensaje, enlace, titulo, imagen);
        Log.i(TAG, "Received: " + extras.toString());
      }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
  }
  @Override
  public void onReceive(Context context, Intent intent) {

    Log.d(TAG, "onHandleIntent - context: " + context);

    // Extract the payload from the message
    Bundle extras = intent.getExtras();
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
    String messageType = gcm.getMessageType(intent);

    if (extras != null) {
      try {
        if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
          JSONObject json = new JSONObject();

          json.put("event", "error");
          json.put("message", extras.toString());
          PushPlugin.sendJavascript(json);
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
          JSONObject json = new JSONObject();
          json.put("event", "deleted");
          json.put("message", extras.toString());
          PushPlugin.sendJavascript(json);
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
          // if we are in the foreground, just surface the payload, else post it to the statusbar
          if (PushPlugin.isInForeground()) {
            extras.putBoolean("foreground", true);
            PushPlugin.sendExtras(extras);
          } else {
            extras.putBoolean("foreground", false);

            // Send a notification if there is a message
            if (extras.getString("message") != null && extras.getString("message").length() != 0) {
              createNotification(context, extras);
            }
          }
        }
      } catch (JSONException exception) {
        Log.d(TAG, "JSON Exception was had!");
      }
    }
  }
  @Override
  protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);

    // The getMessageType() intent parameter must be the intent you receive in your
    // BroadcastReceiver.
    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle

      /*
       * 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(), null);

      } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
        sendNotification("Deleted messages on server: " + extras.toString(), null);

        // If it's a regular GCM message, do some work
      } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
        // Post notification of received message
        String message = extras.toString();

        if (Globals.ACTION_CLEAR_NOTIFICATION.equals(extras.getString("action"))) {
          clearNotification();
        } else if (Globals.ACTION_NOTIFICATION.equals(extras.getString("action"))) {
          sendNotification("Received: " + message, extras);
        } else {
          stopProgressBarIfRequired(extras);
        }
        Log.v(Globals.TAG, "Received: " + message);
      }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
  }
  @Override
  public void onReceive(Context context, Intent intent) {
    ctx = context;
    PowerManager mPowerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    WakeLock mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
    mWakeLock.acquire();
    try {
      GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
      String messageType = gcm.getMessageType(intent);
      if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
        sendNotification("Send error");
      } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
        sendNotification("Deleted messages on server");
      } else {
        String msg = intent.getStringExtra(DataProvider.COL_MESSAGE);
        String senderEmail = intent.getStringExtra(DataProvider.COL_SENDER_EMAIL);
        String receiverEmail = intent.getStringExtra(DataProvider.COL_RECEIVER_EMAIL);
        if (!contactExists(senderEmail, context)) {
          ContentValues values = new ContentValues(2);
          values.put(DataProvider.COL_NAME, senderEmail.substring(0, senderEmail.indexOf('@')));
          values.put(DataProvider.COL_EMAIL, senderEmail);
          context.getContentResolver().insert(DataProvider.CONTENT_URI_PROFILE, values);
        }
        ContentValues values = new ContentValues(2);
        values.put(DataProvider.COL_TYPE, MessageType.INCOMING.ordinal());
        values.put(DataProvider.COL_MESSAGE, msg);
        values.put(DataProvider.COL_SENDER_EMAIL, senderEmail);
        values.put(DataProvider.COL_RECEIVER_EMAIL, receiverEmail);
        context.getContentResolver().insert(DataProvider.CONTENT_URI_MESSAGES, values);

        if (Common.isNotify()) {
          newMessageNotification("New message", senderEmail);
        }
      }
      setResultCode(Activity.RESULT_OK);
    } finally {
      mWakeLock.release();
    }
  }
  @Override
  protected void onHandleIntent(Intent intent) {
    context = getApplicationContext();
    chatArrayAdapter =
        new ChatArrayAdapter(getApplicationContext(), R.layout.activity_chat_singlemessage);
    Bundle extras = intent.getExtras();
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
    String messageType = gcm.getMessageType(intent);

    if (extras != null) {
      if (!extras.isEmpty()) {
        if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
          if ("USERLIST".equals(extras.get("SM"))) {
            // update the userlist view
            Intent userListIntent = new Intent("com.example.admin.yama.userlist");
            String userList = extras.get("USERLIST").toString();
            userListIntent.putExtra("USERLIST", userList);
            sendBroadcast(userListIntent);
          } else if ("CHAT".equals(extras.get("SM"))) {
            Log.v("I WIN", "got a chat here");
            USER_NAME = extras.get("Sender").toString();
            Intent chatIntent = new Intent("com.example.admin.yama.chatmessage");
            chatIntent.putExtra("Sender", extras.get("Sender").toString());
            chatIntent.putExtra("CHATMESSAGE", extras.get("CHATMESSAGE").toString());
            messageNotifictaion(chatIntent);
            sendBroadcast(chatIntent);
          } else if ("SIGNUPACK".equals(extras.get("SM"))) {
            SIGNUP_ACK = "Sign up with server complete";
          } else if (Config.GOOGLE_PROJECT_ID.equals(extras.get("from"))) {
          }
        }
      }
    }
    GcmBroadcastReceiver.completeWakefulIntent(intent);
  }
  @Override
  protected void onHandleIntent(Intent intent) {

    final Bundle extras = intent.getExtras();
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty()) {
      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() , "");
      } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {

        if (extras.getString("webId") != null && !extras.getString("webId").isEmpty()) {

          final PostsDataSource postsDataSource = new PostsDataSource(this);
          postsDataSource.open();

          if (postsDataSource.countRow(
                  DB.POST_TABLE,
                  DB.POST_COLUMNS,
                  DB.POST_COLUMN_WEB_ID + " = ? ",
                  new String[] {extras.getString("webId")},
                  null)
              == 0) {
            new WebClient(
                URL.buildUrl(
                    WebUrl.POST_URL, "20", extras.getString("webId"), null, null, null, null),
                new Response.Listener<String>() {
                  @Override
                  public void onResponse(String response) {
                    List<Post> postList;
                    postList = WebJSONParser.postParseFeed(response);
                    postsDataSource.insertPosts(postList);

                    new Thread(
                            new Runnable() {
                              @Override
                              public void run() {
                                Post post =
                                    postsDataSource.getPost(
                                        DB.POST_COLUMN_WEB_ID + " = ? ",
                                        new String[] {extras.getString("webId")},
                                        null);

                                String url = "";

                                try {

                                  if (post.getType().equals("drama")
                                      || post.getType().equals("column")) {
                                    JSONObject image = null;
                                    image = new JSONObject(post.getCategoryImage());
                                    url = image.getString("small");
                                  } else {
                                    JSONObject image = new JSONObject(post.getImage());
                                    url = image.getString("small");
                                  }

                                } catch (JSONException e) {
                                  e.printStackTrace();
                                }

                                if (!url.isEmpty()) {
                                  Bitmap bitmap = getBitmapFromURL(url);
                                  sendNotification(
                                      "" + extras.get("n"), extras.getString("webId"), bitmap);
                                }
                              }
                            })
                        .start();
                  }
                },
                new Response.ErrorListener() {
                  @Override
                  public void onErrorResponse(VolleyError error) {}
                },
                Request.Priority.HIGH);

          } else {

            new Thread(
                    new Runnable() {
                      @Override
                      public void run() {
                        Post post =
                            postsDataSource.getPost(
                                DB.POST_COLUMN_WEB_ID + " = ? ",
                                new String[] {extras.getString("webId")},
                                null);

                        String url = "";

                        try {

                          if (post.getType().equals("drama") || post.getType().equals("column")) {
                            JSONObject image = null;
                            image = new JSONObject(post.getCategoryImage());
                            url = image.getString("small");
                          } else {
                            JSONObject image = new JSONObject(post.getImage());
                            url = image.getString("small");
                          }

                        } catch (JSONException e) {
                          e.printStackTrace();
                        }

                        if (!url.isEmpty()) {
                          Bitmap bitmap = getBitmapFromURL(url);
                          sendNotification("" + extras.get("n"), extras.getString("webId"), bitmap);
                        }
                      }
                    })
                .start();
          }
        }
      }
    }

    GcmBroadcastReceiver.completeWakefulIntent(intent);
  }