Java Code Examples for android.telephony.SmsMessage#getTimestampMillis()

The following examples show how to use android.telephony.SmsMessage#getTimestampMillis() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IncomingTextMessage.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
public IncomingTextMessage(@NonNull RecipientId sender, @NonNull SmsMessage message, int subscriptionId) {
  this.message               = message.getDisplayMessageBody();
  this.sender                = sender;
  this.senderDeviceId        = SignalServiceAddress.DEFAULT_DEVICE_ID;
  this.protocol              = message.getProtocolIdentifier();
  this.serviceCenterAddress  = message.getServiceCenterAddress();
  this.replyPathPresent      = message.isReplyPathPresent();
  this.pseudoSubject         = message.getPseudoSubject();
  this.sentTimestampMillis   = message.getTimestampMillis();
  this.serverTimestampMillis = -1;
  this.subscriptionId        = subscriptionId;
  this.expiresInMillis       = 0;
  this.groupId               = null;
  this.push                  = false;
  this.unidentified          = false;
}
 
Example 2
Source File: IncomingTextMessage.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
public IncomingTextMessage(@NonNull AccountContext accountContext,
                           @NonNull SmsMessage message,
                           int subscriptionId) {
    this.message = message.getDisplayMessageBody();
    this.payloadType = parseBodyPayloadType(this.message);
    this.sender = Address.from(accountContext, message.getDisplayOriginatingAddress());
    this.senderDeviceId = SignalServiceAddress.DEFAULT_DEVICE_ID;
    this.protocol = message.getProtocolIdentifier();
    this.serviceCenterAddress = message.getServiceCenterAddress();
    this.replyPathPresent = message.isReplyPathPresent();
    this.pseudoSubject = message.getPseudoSubject();
    this.sentTimestampMillis = message.getTimestampMillis();
    this.subscriptionId = subscriptionId;
    this.expiresInMillis = 0;
    this.groupId = null;
    this.push = false;
}
 
Example 3
Source File: AssistantService.java    From AssistantBySDK with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    //先判断广播消息
    String action = intent.getAction();
    if (SMS_RECEIVED_ACTION.equals(action) || GSM_SMS_RECEIVED_ACTION.equals(action)) {
        //获取intent参数
        Bundle bundle = intent.getExtras();
        //判断bundle内容
        if (bundle != null) {
            //取pdus内容,转换为Object[]
            Object[] pdus = (Object[]) bundle.get("pdus");
            //解析完内容后分析具体参数
            String sender = null, content = "", lastContent = "";
            long date = 0;
            SmsInfo sms = new SmsInfo();
            for (int i = 0; i < pdus.length; i++) {
                SmsMessage msg = SmsMessage.createFromPdu((byte[]) pdus[i]);
                content = lastContent.length() >= msg.getMessageBody().length() ? content + msg.getMessageBody() : msg.getMessageBody() + content;
                lastContent = msg.getMessageBody();
                sender = msg.getOriginatingAddress();
                date = msg.getTimestampMillis();
                if (TextUtils.isEmpty(sender) && sender.startsWith("+86"))
                    sender = sender.substring(3);
            }
            sms.setTime(date);
            sms.setContent(content);
            StringBuilder number = new StringBuilder(sender);
            processors.get(BaseProcessor.CMD_CALL).receiveSms(sms, number);
        }
    }
}
 
Example 4
Source File: IncomingTextMessage.java    From Silence with GNU General Public License v3.0 5 votes vote down vote up
public IncomingTextMessage(SmsMessage message, int subscriptionId, boolean receivedWhenLocked) {
  this.message              = message.getDisplayMessageBody();
  this.sender               = message.getDisplayOriginatingAddress();
  this.senderDeviceId       = 1;
  this.protocol             = message.getProtocolIdentifier();
  this.serviceCenterAddress = message.getServiceCenterAddress();
  this.replyPathPresent     = message.isReplyPathPresent();
  this.pseudoSubject        = message.getPseudoSubject();
  this.sentTimestampMillis  = message.getTimestampMillis();
  this.subscriptionId       = subscriptionId;
  this.groupId              = null;
  this.push                 = false;
  this.receivedWhenLocked   = receivedWhenLocked;
}
 
Example 5
Source File: Db.java    From medic-gateway with GNU Affero General Public License v3.0 4 votes vote down vote up
@SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE") // for #117
boolean store(SmsMessage sms) {
	SmsUdh multi = SmsUdh.from(sms);

	if(multi == null || multi.totalParts == 1) {
		WtMessage m = new WtMessage(
				sms.getOriginatingAddress(),
				sms.getMessageBody(),
				sms.getTimestampMillis());
		return store(m);
	} else {
		try {
			long id = db.insertOrThrow(tblWT_MESSAGE_PART, null, getContentValues(sms, multi));

			if(id == -1) return false;
		} catch(SQLiteConstraintException ex) {
			logException(ex, "Failed to save multipart fragment - it likely already exists in the database.");
			return false;
		}

		Cursor c = null;
		db.beginTransaction();

		try {
			c = db.query(tblWT_MESSAGE_PART,
					cols(WMP_clmCONTENT),
					eq(WMP_clmFROM, WMP_clmMP_REF),
					args(sms.getOriginatingAddress(), multi.multipartRef),
					NO_GROUP, NO_GROUP,
					SortDirection.ASC.apply(WMP_clmMP_PART));
			if(c.getCount() == multi.totalParts) {
				StringBuilder bob = new StringBuilder();
				while(c.moveToNext()) {
					bob.append(c.getString(0));
				}
				boolean success = store(new WtMessage(sms.getOriginatingAddress(), bob.toString(), multi.sentTimestamp));
				if(success) {
					rawUpdateOrDelete("DELETE FROM %s WHERE %s=? AND %s=?",
							cols(tblWT_MESSAGE_PART, WMP_clmFROM, WMP_clmMP_REF),
							args(sms.getOriginatingAddress(), multi.multipartRef));
					db.setTransactionSuccessful();
				} else {
					return false;
				}
			}
			return true;
		} finally {
			db.endTransaction();
			if(c != null) c.close();
		}
	}
}