Code example for SmsMessage

Methods: getDisplayMessageBodygetDisplayOriginatingAddresstoString

0
Bundle pudsBundle = intent.getExtras();
 
		Object[] pdus = (Object[]) pudsBundle.get("pdus");
		sms = SmsMessage.createFromPdu((byte[]) pdus[0]);
		Log.i(TAG, sms.toString());
 
		if (mTts == null)
		{ 
			mTts = new TextToSpeech(context.getApplicationContext(), this);
		} 
 
		String intro = "Incoming message";
		String from = sms.getDisplayOriginatingAddress();
		if (from != null)
		{ 
 
			Cursor c = null;
			try 
			{ 
				Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(from));
 
				c = resolver
						.query(uri, new String[] { PhoneLookup.DISPLAY_NAME }, null, null, null);
 
				if (c.getCount() > 0)
				{ 
					c.moveToFirst();
 
					from = c.getString(0);
				} 
			} finally 
			{ 
				if (c != null)
				{ 
					c.close();
				} 
			} 
 
			intro += " from";
		} 
 
		messages.offer(new Message(intro, from, sms.getDisplayMessageBody()));
 
		return super.onStartCommand(intent, flags, startId);
	} 
 
	@SuppressWarnings("deprecation")