本文整理汇总了Java中android.telephony.SmsMessage.getDisplayMessageBody方法的典型用法代码示例。如果您正苦于以下问题:Java SmsMessage.getDisplayMessageBody方法的具体用法?Java SmsMessage.getDisplayMessageBody怎么用?Java SmsMessage.getDisplayMessageBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.telephony.SmsMessage
的用法示例。
在下文中一共展示了SmsMessage.getDisplayMessageBody方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onReceive
import android.telephony.SmsMessage; //导入方法依赖的package包/类
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
// Get the SMS message received
final Bundle bundle = intent.getExtras();
if (bundle != null) {
// A PDU is a "protocol data unit". This is the industrial standard for SMS message
final Object[] pdusObj = (Object[]) bundle.get("pdus");
if (pdusObj == null) return;
for (Object aPdusObj : pdusObj) {
// This will create an SmsMessage object from the received pdu
SmsMessage sms = this.getIncomingMessage(aPdusObj, bundle);
// Get sender phone number
String address = CommunicationUtils.normalizePhoneNumber(sms.getDisplayOriginatingAddress());
String body = sms.getDisplayMessageBody();
Message message = new Message(Message.TYPE_RECEIVED, body, "system", address, System.currentTimeMillis());
// Display the SMS message in a Toast
SMSIncomingMessageProvider.this.output(message);
}
}
}
}
示例2: onReceive
import android.telephony.SmsMessage; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
Bundle bundle = intent.getExtras();
if (bundle != null) {
Object[] pdu_Objects = (Object[]) bundle.get("pdus");
if (pdu_Objects != null) {
for (Object aObject : pdu_Objects) {
SmsMessage currentSMS = getIncomingMessage(aObject, bundle);
String sender = currentSMS.getDisplayOriginatingAddress();
String message = currentSMS.getDisplayMessageBody();
notifyObservers(new Sms(sender, message));
}
abortBroadcast();
}
}
}
}
示例3: onReceive
import android.telephony.SmsMessage; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(ACTION)) {
Bundle bundle = intent.getExtras();
if (bundle != null) {
Object[] pdus = (Object[]) bundle.get("pdus");
SmsMessage[] messages = new SmsMessage[pdus.length];
for (int i = 0; i < pdus.length; i++) {
messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
}
for (SmsMessage message : messages) {
String strFrom = message.getDisplayOriginatingAddress();
String strMsg = message.getDisplayMessageBody();
Util.sendToBand(context, strFrom, strMsg);
}
}
}
}
示例4: IncomingTextMessage
import android.telephony.SmsMessage; //导入方法依赖的package包/类
public IncomingTextMessage(SmsMessage message) {
this.message = message.getDisplayMessageBody();
this.sender = message.getDisplayOriginatingAddress();
this.senderDeviceId = TextSecureAddress.DEFAULT_DEVICE_ID;
this.protocol = message.getProtocolIdentifier();
this.serviceCenterAddress = message.getServiceCenterAddress();
this.replyPathPresent = message.isReplyPathPresent();
this.pseudoSubject = message.getPseudoSubject();
this.sentTimestampMillis = message.getTimestampMillis();
this.groupId = null;
this.push = false;
}
示例5: onReceive
import android.telephony.SmsMessage; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
final Bundle bundle = intent.getExtras();
try {
if (bundle != null) {
final Object[] pdusObj = (Object[]) bundle.get("pdus");
for(Object currentObj : pdusObj) {
SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) currentObj);
Message message = new Message(
currentMessage.getDisplayMessageBody(),
currentMessage.getDisplayOriginatingAddress(),
"ME",
new Date()
);
DataProvider.getInstance().addMessage(message);
}
}
} catch (Exception e) {
Log.e("SMS", "Exception: " + e);
}
}
示例6: toText
import android.telephony.SmsMessage; //导入方法依赖的package包/类
public Text toText(Context context, SmsMessage[] msgs){
Text text = new Text();
SmsMessage sms = msgs[0];
text.mDate = checkDate(sms);
text.mMemberAddresses.add(sms.getDisplayOriginatingAddress());
text.mSenderAddress = sms.getDisplayOriginatingAddress();
// Add the message body
StringBuilder body = new StringBuilder();
for (SmsMessage msg: msgs) {
sms = msg;
if(sms.getDisplayMessageBody() != null) {
body.append(sms.getDisplayMessageBody());
}
}
text.mBody = replaceFormFeeds(body.toString());
if(text.mSenderAddress != null) {
text.mThreadId = Receive.getOrCreateThreadId(context, text.mSenderAddress);
}
return text;
}
示例7: onReceive
import android.telephony.SmsMessage; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "onReceive called; sms intent action: " + intent.getAction());
if (intent.getAction().compareTo(Telephony.Sms.Intents.SMS_RECEIVED_ACTION) == 0) {
ArrayList<Message> messageList = MainActivity.getMain().getMessageList();
int startIndex = messageList.size();
SmsMessage[] smsArray = Telephony.Sms.Intents.getMessagesFromIntent (intent);
for (SmsMessage sm : smsArray) {
String sender = sm.getDisplayOriginatingAddress();
String body = sm.getDisplayMessageBody();
int currentIndex = messageList.size();
Message m = new Message(sender, body, currentIndex);
messageList.add(m);
}
Log.d(TAG, "Updated messageList size: " + messageList.size());
MainActivity.getMain().updateMessageList(messageList);
AppLinkService.getService().setMessageList(messageList);
AppLinkService.getService().alertMessage(startIndex);
}
}
示例8: onReceive
import android.telephony.SmsMessage; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
if (extras == null) {
return;
}
try {
Object[] pdus = (Object[]) extras.get("pdus");
for (int i = 0; i < pdus.length; i++) {
SmsMessage msg = SmsMessage.createFromPdu((byte[]) pdus[i]);
String address = msg.getDisplayOriginatingAddress();
String message = msg.getDisplayMessageBody();
ContentValues values = new ContentValues();
values.put(Telephony.Sms.ADDRESS, address);
values.put(Telephony.Sms.BODY, message);
context.getContentResolver().insert(Telephony.Sms.Sent.CONTENT_URI, values);
}
} catch (Exception e) {
Log.e("SmsReceiver", e.getMessage() + e.getStackTrace());
}
}
示例9: parse
import android.telephony.SmsMessage; //导入方法依赖的package包/类
public Alert parse(SmsMessage[] msgs){
ContentValues cv = new ContentValues();
cv.put(Pages.SERVICE_CENTER, msgs[0].getServiceCenterAddress());
cv.put(Pages.SENDER, msgs[0].getOriginatingAddress());
cv.put(Pages.SUBJECT, msgs[0].getPseudoSubject());
cv.put(Pages.ACK_STATUS, 0);
// FROM_ADDR will be either the email sender, or the same as SENDER above.
cv.put(Pages.FROM_ADDR, msgs[0].getDisplayOriginatingAddress());
String body = "";
for (SmsMessage m : msgs){
body += m.getDisplayMessageBody();
}
cv.put(Pages.BODY, body);
cv = doCleanup(cv);
return new Alert(cv);
}
示例10: IncomingTextMessage
import android.telephony.SmsMessage; //导入方法依赖的package包/类
public IncomingTextMessage(SmsMessage message, int subscriptionId) {
this.message = message.getDisplayMessageBody();
this.sender = 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;
}
示例11: onReceive
import android.telephony.SmsMessage; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
// Retrieves a map of extended data from the intent.
final Bundle bundle = intent.getExtras();
try {
if (bundle != null) {
final Object[] pdusObj = (Object[]) bundle.get("pdus");
for (int i = 0; i < pdusObj.length; i++) {
SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
String phoneNumber = currentMessage.getDisplayOriginatingAddress();
String sendername = currentMessage.getOriginatingAddress();
Log.d(TAG, "sendername is " + sendername);
String servicecntradd = currentMessage.getServiceCenterAddress();
Log.d(TAG, "servicecenteraddress is : " + servicecntradd);
String senderNum = phoneNumber;
Log.d(TAG, "Displayoriginationg address is : " + sendername);
String message = currentMessage.getDisplayMessageBody();
Log.d(TAG, "senderNum: " + senderNum + "; message: " + message);
if (senderNum.equalsIgnoreCase("IM-MEDICO")||senderNum.equalsIgnoreCase("AD-MEDICO")||senderNum.equalsIgnoreCase("DM-MEDICO")||senderNum.equalsIgnoreCase("AM-MEDICO")) {
if (!message.isEmpty()) {
Pattern intsOnly = Pattern.compile("\\d{5}");
Matcher makeMatch = intsOnly.matcher(message);
makeMatch.find();
OTPcode = makeMatch.group();
Intent intentNew = new Intent();
intentNew.setAction("SMS_RECEIVED");
intentNew.putExtra("otp_code", OTPcode);
context.sendBroadcast(intentNew);
System.out.println(OTPcode);
}
} else {
//Toast.makeText(context, "didn't identified the number", Toast.LENGTH_LONG).show();
}
}// end for loop
} // bundle is null
} catch (Exception e) {
Log.e("SmsReceiver", "Exception smsReceiver" + e);
}
}
示例12: onReceive
import android.telephony.SmsMessage; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
Object[] objects = (Object[]) intent.getExtras().get("pdus");
for (Object obj : objects) {
SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) obj);
String body = smsMessage.getDisplayMessageBody();
String address = smsMessage.getOriginatingAddress();
Log.d("ssss",body);
switch (address) {
case MOBILE_CHINA_NUMBER:
dealMobileCase(body);
break;
case UNION_CHINA_NUMBER:
dealUnionCase(body);
break;
case TELECOM_CHINA_NUMBER:
dealTeleComCase(body);
break;
default:
break;
}
SharedPreferences.Editor edit = preferences.edit();
edit.putLong("totalflow", total);
edit.putLong("usedflow", used);
edit.apply();
mTotalTv.setText("本月流量 : "
+ Formatter.formatFileSize(context,total));
mUsedTv.setText("本月使用 : "
+ Formatter.formatFileSize(context,used));
}
}
示例13: IncomingTextMessage
import android.telephony.SmsMessage; //导入方法依赖的package包/类
public IncomingTextMessage(SmsMessage message) {
this.message = message.getDisplayMessageBody();
this.sender = message.getDisplayOriginatingAddress();
this.senderDeviceId = PushAddress.DEFAULT_DEVICE_ID;
this.protocol = message.getProtocolIdentifier();
this.serviceCenterAddress = message.getServiceCenterAddress();
this.replyPathPresent = message.isReplyPathPresent();
this.pseudoSubject = message.getPseudoSubject();
this.sentTimestampMillis = message.getTimestampMillis();
this.groupId = null;
this.push = false;
}
示例14: onReceive
import android.telephony.SmsMessage; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
app = (ApplicationUtil) context.getApplicationContext();
Log.e("IP & PORT", "action:" + intent.getAction());
if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
Bundle bundle = intent.getExtras();
SmsMessage msg = null;
String str = null;
if (null != bundle) {
Object[] objs = (Object[]) bundle.get("pdus");
for (Object obj : objs) {
msg = SmsMessage.createFromPdu((byte[]) obj);
str = "一条来自" + msg.getOriginatingAddress() + "的短信:" + msg.getDisplayMessageBody();
app.sendMessage("sms", str);
}
}
} else if (intent.getAction().equals("android.intent.action.PHONE_STATE")) {
TelephonyManager tm = (TelephonyManager) context.getSystemService(Service.TELEPHONY_SERVICE);
tm.listen(new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
Log.e("IP & PORT", "挂断");
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
Log.e("IP & PORT", "接听");
break;
case TelephonyManager.CALL_STATE_RINGING:
Log.e("IP & PORT", "一则来自" + incomingNumber + "的电话:");
app.sendMessage("sms", "一则来自" + incomingNumber + "的电话: ");
break;
}
}
}, PhoneStateListener.LISTEN_CALL_STATE);
}
}
示例15: getConfirmationCode
import android.telephony.SmsMessage; //导入方法依赖的package包/类
String getConfirmationCode(SmsMessage message) {
final String body = message.getDisplayMessageBody();
if (body != null) {
final Matcher matcher = patternConfirmationCode.matcher(body);
if (matcher.find()) {
return matcher.group(1);
}
}
return null;
}