Beispiel #1
0
        public void processMessage(Chat chat, Message message) {
          if ((message.getBody() != null) && (!message.getType().equals(Message.Type.error))) {
            if (!cipher) {

              Log.i(TAG, "Recibido mensaje plano: " + message.getBody());
              listMessages.add(message);
              refreshAdapter();
              myListView.smoothScrollToPosition(adapter.getCount() - 1);
            } else {

              try {
                PrivateKey pk =
                    RSA.getPrivateKeyDecryted(KeyStore.getInstance().getPk(), passPhrase);
                String decodedMessage = RSA.decipher(message.getBody(), pk);
                Log.i(TAG, "Recibido mensaje cifrado: " + decodedMessage);

                Message m = new Message();
                m.setFrom(message.getFrom());
                m.setTo(message.getTo());

                m.setBody(decodedMessage);
                SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
                m.setSubject(sdf.format(new Date()));
                listMessages.add(m);
                refreshAdapter();
                myListView.smoothScrollToPosition(adapter.getCount() - 1);

              } catch (Exception e) {
                Log.d(TAG, "PETO AL DESCIFRAR");
                e.printStackTrace();
              }
            }
          }
        }
Beispiel #2
0
  public void broadcast() throws XMPPException {

    Message newmsg = new Message();
    newmsg.setTo("*****@*****.**");
    newmsg.setSubject("重要通知");
    newmsg.setBody("今天下午2点60分有会!");
    newmsg.setType(Message.Type.headline); // normal支持离线
    connection.sendPacket(newmsg);
    connection.disconnect();
  }
  public void sendQuery(View v) {

    showMessage = new Builder(this);

    try {
      List<JSONObject> query = generatePayload();
      if (fromDt.getTime() > System.currentTimeMillis()) {
        if (validity) {
          // PubSubManager mgr = new
          // PubSubManager(RegisterMe.conn);
          Iterator<JSONObject> traverse = query.iterator();
          while (traverse.hasNext()) {
            Message query2 = new Message("[email protected]", Message.Type.chat);
            query2.setSubject("Query");
            query2.setBody(traverse.next().toString());
            // System.out.println(query2.getBody());
            RegisterMe.conn.sendPacket(query2);
          }
          showMessage.setTitle("Query Submission").setMessage("Successful").create().show();
          // System.out.println("Sensors selected:"+
          // query.size());
          /*try {
          			Message query2 = new Message("[email protected]",
          			Message.Type.chat);
          	query2.setSubject("Query");
          	query2.setBody(query.toString());
          //	RegisterMe.conn.sendPacket(query2);
          	showMessage.setTitle("Query Submission")
          			.setMessage("Successful").create().show();

          } catch (Exception e) {
          	// TODO Auto-generated catch block
          	e.printStackTrace();
          }*/
        } else {
          showMessage.setTitle("Error!").setMessage("Invalid fields!").create().show();
        }
      } else {
        showMessage.setTitle("Error!").setMessage("Starting Time already passed!").create().show();
      }
    } catch (Exception e) {
      showMessage
          .setTitle("Error!")
          .setMessage("Please ensure that data entered is valid")
          .create()
          .show();
    }
  }
Beispiel #4
0
  public void send(View view) {
    Message message = new Message(destJid);
    EditText editText = (EditText) findViewById(R.id.textInput);
    String plainText = editText.getText().toString();
    editText.setText("");

    message.setFrom(myJid);
    message.setTo(destJid);

    Message m = new Message();
    m.setFrom(myJid);
    m.setBody(plainText);
    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
    m.setSubject(sdf.format(new Date()));
    listMessages.add(m);
    refreshAdapter();
    myListView.smoothScrollToPosition(adapter.getCount() - 1);

    if (!cipher) {
      try {
        message.setBody(plainText);
        chatMan.getChat().sendMessage(message);
        Log.d(TAG, "Enviando: " + message.getBody());

      } catch (XMPPException e) {
        Log.d(TAG, "ERROR al enviar mensaje");
      }
    } else {
      try {
        String encodedMessage = RSA.cipher(plainText, cert.getPublicKey());
        message.setBody(encodedMessage);
        chatMan.getChat().sendMessage(message);
        Log.d(TAG, "Enviando cifrado: " + message.getBody() + " " + plainText);

      } catch (Exception e) {
        Log.d(TAG, "PETO ENVIANDO CIFRADOOOO");
        e.printStackTrace();
      }
    }
  }