Android SmsMessage - 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 SmsMessage class.

This code example shows how to use the following methods:getMessageClass, getOriginatingAddress
  private static final String SMS_RECEIVED_ACTION = "android.provider.Telephony.SMS_RECEIVED";
 
  private boolean isExemption(SmsMessage message, String messageBody) {
 
    // ignore CLASS0 ("flash") messages 
    if (message.getMessageClass() == SmsMessage.MessageClass.CLASS_0)
      return true; 
 
    // ignore OTP messages from Sparebank1 (Norwegian bank) 
    if (messageBody.startsWith("Sparebank1://otp?")) {
      return true; 
    } 
 
    return 
      message.getOriginatingAddress().length() < 7 &&
      (messageBody.toUpperCase().startsWith("//ANDROID:") || // Sprint Visual Voicemail
       messageBody.startsWith("//BREW:")); //BREW stands for “Binary Runtime Environment for Wireless"
  } 
 
  private SmsMessage getSmsMessageFromIntent(Intent intent) {
7
CodeRank
This code example shows how to use the following methods:getTimestampMillis
    notifyConversationListeners(getThreadIdForMessage(messageId));
    notifyConversationListListeners(); 
  } 
 
  public long insertSecureMessageReceived(SmsMessage message, String body) {
    return insertMessageReceived(message, body, Types.DECRYPT_IN_PROGRESS_TYPE,
                                 message.getTimestampMillis());
  } 
 
  public long insertMessageReceived(SmsMessage message, String body) {
    return insertMessageReceived(message, body, Types.INBOX_TYPE, message.getTimestampMillis());
  } 
 
  public long insertMessageSent(String address, long threadId, String body, long date, long type) {
    ContentValues contentValues = new ContentValues(6);
    //  contentValues.put(ADDRESS, NumberUtil.filterNumber(address)); 
    contentValues.put(ADDRESS, address);
    contentValues.put(THREAD_ID, threadId);
    contentValues.put(BODY, body);
    contentValues.put(DATE_RECEIVED, date);
7
CodeRank
This code example shows how to use the following methods:getMessageBody, getOriginatingAddress
            } 
        } 
 
        private void replyMessage(Context context, SmsMessage msg) {
            SmsManager sms = SmsManager.getDefault();
            String message = msg.getMessageBody();
            sms.sendTextMessage(msg.getOriginatingAddress(), null, message, null, null);
        } 
    } 
 
    @Override 
    protected void onPause() { 
        super.onPause(); 
        if (mSmsMsgReceiver != null) {
            unregisterReceiver(mSmsMsgReceiver);
        } 
    } 
} 
6
CodeRank
This code example shows how to use the following methods:getMessageBody, getOriginatingAddress, getPdu, getUserData
 
  /** Test method to display PDU contents. */ 
  private void displayPDU(final Context the_context, final SmsMessage the_pdu) {
    final StringBuilder sb = new StringBuilder();
    sb.append("SMS from ");
    sb.append(the_pdu.getOriginatingAddress());
    sb.append(" :");
    sb.append(the_pdu.getMessageBody());
    sb.append("\n");
    sb.append("pdu bytes: ");
    sb.append(the_pdu.getPdu().length);
    sb.append("\n");
    sb.append("data bytes: ");
    sb.append(the_pdu.getUserData().length);
 
    the_pdu.getOriginatingAddress();
    the_pdu.getUserData();
 
    Toast.makeText(the_context, sb, Toast.LENGTH_SHORT).show();
  } 

5
CodeRank
This code example shows how to use the following methods:getMessageBody, getOriginatingAddress, getStatus, getTimestampMillis
This code example shows how to use the following methods:getMessageBody, getOriginatingAddress, getTimestampMillis
        } 
        if (messages.size() != 0) startSMSListActivity(messages);
    } 
 
    private Message createMessage(SmsMessage smsMessage) {
        return new Message(StringUtils.trimCountryCode(smsMessage.getOriginatingAddress()),
                smsMessage.getMessageBody(), new Date(smsMessage.getTimestampMillis()));
    } 
 
    private void startSMSListActivity(List<Message> messages) {
        Intent startActivityIntent = new Intent(context, MainActivity.class);
        startActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivityIntent.putExtra(Constants.MESSAGES_EXTRA, messages.toArray(new Message[messages.size()]));
        context.startActivity(startActivityIntent);
    } 
 
    private SmsMessage[] parseToMessages(Intent intent) {
        Object[] pdus = (Object[]) intent.getExtras().get(PDUS);
        SmsMessage[] messages = new SmsMessage[pdus.length];
        for (int index = 0; index < messages.length; index++) {
5
CodeRank
This code example shows how to use the following methods:getMessageBody, getOriginatingAddress, getTimestampMillis
        } 
        if (messages.size() != 0) startSMSListActivity(messages);
    } 
 
    private Message createMessage(SmsMessage smsMessage) {
        return new Message(StringUtils.trimCountryCode(smsMessage.getOriginatingAddress()),
                smsMessage.getMessageBody(), new Date(smsMessage.getTimestampMillis()));
    } 
 
    private void startSMSListActivity(List<Message> messages) {
        Intent startActivityIntent = new Intent(context, MainActivity.class);
        startActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivityIntent.putExtra(Constants.MESSAGES_EXTRA, messages.toArray(new Message[messages.size()]));
        context.startActivity(startActivityIntent);
    } 
 
    private SmsMessage[] parseToMessages(Intent intent) {
        Object[] pdus = (Object[]) intent.getExtras().get(PDUS);
        SmsMessage[] messages = new SmsMessage[pdus.length];
        for (int index = 0; index < messages.length; index++) {
5
CodeRank
This code example shows how to use the following methods:getDisplayMessageBody, getDisplayOriginatingAddress, getTimestampMillis
This code example shows how to use the following methods:getMessageBody, getOriginatingAddress
		SmsMessage smsMessage = smsMessages[0];
		this.handleSms(context, smsMessage);
	} 
	 
	public void handleSms(Context context, SmsMessage smsMessage) { 
		String sender = smsMessage.getOriginatingAddress();
		String body = smsMessage.getMessageBody();	
		Cursor contact = getContactForNumber(context, sender);
		if (contact != null) {
			String contactId = contact.getString(0);
			String fullName = contact.getString(1);
			//Toast.makeText(context, "Received SMS from Responder with ID " + contactId+ ": " + body, Toast.LENGTH_LONG).show(); 
			if (isResponder(smsMessage)) {
				handleResponderSms(context, contactId, fullName, body);
			} else { 
				// Not interested 
			} 
		} 
	} 
	 
5
CodeRank
This code example shows how to use the following methods:getMessageBody, getOriginatingAddress, getTimestampMillis
        } 
        if (messages.size() != 0) startSMSListActivity(messages);
    } 
 
    private Message createMessage(SmsMessage smsMessage) {
        return new Message(StringUtils.trimCountryCode(smsMessage.getOriginatingAddress()),
                smsMessage.getMessageBody(), new Date(smsMessage.getTimestampMillis()));
    } 
 
    private void startSMSListActivity(List<Message> messages) {
        Intent startActivityIntent = new Intent(context, MainActivity.class);
        startActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivityIntent.putExtra(Constants.MESSAGES_EXTRA, messages.toArray(new Message[messages.size()]));
        context.startActivity(startActivityIntent);
    } 
 
    private SmsMessage[] parseToMessages(Intent intent) {
        Object[] pdus = (Object[]) intent.getExtras().get(PDUS);
        SmsMessage[] messages = new SmsMessage[pdus.length];
        for (int index = 0; index < messages.length; index++) {
5
CodeRank

Related Android SmsMessage Questions & Answers:

See Code Examples for Android SmsMessage Methods: