本文整理汇总了Java中android.telephony.SmsMessage类的典型用法代码示例。如果您正苦于以下问题:Java SmsMessage类的具体用法?Java SmsMessage怎么用?Java SmsMessage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SmsMessage类属于android.telephony包,在下文中一共展示了SmsMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onReceive
import android.telephony.SmsMessage; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED") && intent.getExtras() != null) {
favoriteContacts = CustodeUtils.getFavoriteContacts(context);
Object[] data = (Object[]) intent.getExtras().get("pdus");
if (data != null)
for (Object pdu : data) {
SmsMessage message;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
String format = intent.getExtras().getString("format");
message = SmsMessage.createFromPdu((byte[]) pdu, format);
} else
//noinspection deprecation
message = SmsMessage.createFromPdu((byte[]) pdu);
if (message != null)
processSMS(context, message);
}
}
}
示例2: getMessagesFromIntent
import android.telephony.SmsMessage; //导入依赖的package包/类
/**
* Parse the messages out of the extra fields from the "android.permission.RECEIVE_SMS" broadcast
* intent.
*
* Note: This code was copied from the Android android.provider.Telephony.Sms.Intents class.
*
* @param intent the intent to read from
* @return an array of SmsMessages for the PDUs
*/
public static SmsMessage[] getMessagesFromIntent(
Intent intent) {
Object[] messages = (Object[]) intent.getSerializableExtra("pdus");
byte[][] pduObjs = new byte[messages.length][];
for (int i = 0; i < messages.length; i++) {
pduObjs[i] = (byte[]) messages[i];
}
byte[][] pdus = new byte[pduObjs.length][];
int pduCount = pdus.length;
SmsMessage[] msgs = new SmsMessage[pduCount];
for (int i = 0; i < pduCount; i++) {
pdus[i] = pduObjs[i];
msgs[i] = SmsMessage.createFromPdu(pdus[i]);
}
return msgs;
}
示例3: handleSmsReceived
import android.telephony.SmsMessage; //导入依赖的package包/类
private void handleSmsReceived(Intent intent, int error) {
SmsMessage[] msgs = Intents.getMessagesFromIntent(intent);
String format = intent.getStringExtra("format");
Uri messageUri = insertMessage(this, msgs, error, format);
if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE) || LogTag.DEBUG_SEND) {
SmsMessage sms = msgs[0];
Log.v(TAG, "handleSmsReceived" + (sms.isReplace() ? "(replace)" : "") +
" messageUri: " + messageUri +
", address: " + sms.getOriginatingAddress() +
", body: " + sms.getMessageBody());
}
if (messageUri != null) {
long threadId = MessagingNotification.getSmsThreadId(this, messageUri);
// Called off of the UI thread so ok to block.
Log.d(TAG, "handleSmsReceived messageUri: " + messageUri + " threadId: " + threadId);
MessagingNotification.blockingUpdateNewMessageIndicator(this, threadId, false);
}
}
示例4: onReceive
import android.telephony.SmsMessage; //导入依赖的package包/类
public void onReceive(Context context, Intent intent) {
if(ACTION_SMS_RECEIVER.equals(intent.getAction())) {
Bundle bundle = intent.getExtras();
if(bundle != null) {
Object[] pdus = (Object[]) bundle.get("pdus");
SmsMessage[] smsArr = new SmsMessage[pdus.length];
for (int i = 0; i < pdus.length; i++) {
smsArr[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
}
for (SmsMessage sms: smsArr) {
if(sms != null) {
SMSSDK.readVerificationCode(sms, listener);
}
}
}// END if(bundle != null)
}
}
示例5: 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);
}
}
}
}
示例6: getSmsCodeFromReceiver
import android.telephony.SmsMessage; //导入依赖的package包/类
/**
* 包访问级别:提高性能
* 从接收者中得到短信验证码
*
* @param intent
*/
void getSmsCodeFromReceiver(Intent intent) {
SmsMessage[] messages = null;
if (Build.VERSION.SDK_INT >= 19) {
messages = android.provider.Telephony.Sms.Intents.getMessagesFromIntent(intent);
if (messages == null) return;
} else {
messages = getSmsUnder19(intent);
if (messages == null) return;
}
if (messages.length > 0) {
for (int i = 0; i < messages.length; i++) {
SmsMessage sms = messages[i];
String smsSender = sms.getOriginatingAddress();
String smsBody = sms.getMessageBody();
if (checkSmsSender(smsSender) && checkSmsBody(smsBody)) {
String smsCode = parseSmsBody(smsBody);
sendMsg2Register(OBSERVER_SMS_CODE_MSG, smsCode);
break;
}
}
}
}
示例7: getSmsUnder19
import android.telephony.SmsMessage; //导入依赖的package包/类
@Nullable
private SmsMessage[] getSmsUnder19(Intent intent) {
SmsMessage[] messages;
Bundle bundle = intent.getExtras();
// 相关链接:https://developer.android.com/reference/android/provider/Telephony.Sms.Intents.html#SMS_DELIVER_ACTION
Object[] pdus = (Object[]) bundle.get("pdus");
if ((pdus == null) || (pdus.length == 0)) {
return null;
}
messages = new SmsMessage[pdus.length];
for (int i = 0; i < pdus.length; i++) {
messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
}
return messages;
}
示例8: isExemption
import android.telephony.SmsMessage; //导入依赖的package包/类
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"
}
示例9: calculateCharacters
import android.telephony.SmsMessage; //导入依赖的package包/类
@Override
public CharacterState calculateCharacters(String messageBody) {
int[] length = SmsMessage.calculateLength(messageBody, false);
int messagesSpent = length[0];
int charactersSpent = length[1];
int charactersRemaining = length[2];
int maxMessageSize;
if (messagesSpent > 0) {
maxMessageSize = (charactersSpent + charactersRemaining) / messagesSpent;
} else {
maxMessageSize = (charactersSpent + charactersRemaining);
}
return new CharacterState(messagesSpent, charactersRemaining, maxMessageSize);
}
示例10: onReceive
import android.telephony.SmsMessage; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
Object[] rawMsgs=(Object[])intent.getExtras().get("pdus");
for (Object raw : rawMsgs) {
//int activePhone = TelephonyManager.getDefault().getCurrentPhoneType();
//String format = (PHONE_TYPE_CDMA == activePhone) ? SmsConstants.FORMAT_3GPP2 : SmsConstants.FORMAT_3GPP;
SmsMessage msg = SmsMessage.createFromPdu((byte[])raw);
Log.w("SMS:"+msg.getOriginatingAddress(), msg.getMessageBody());
if (msg.getMessageBody().toUpperCase().contains("IF710")) {//iF1001 if1001 If1001
Intent i = new Intent(context,SmsReceivedActivity.class);
i.putExtra("msgFrom",msg.getOriginatingAddress());
i.putExtra("msgBody",msg.getMessageBody());
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
abortBroadcast();
}
}
}
示例11: onReceive
import android.telephony.SmsMessage; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
Logger.d("SMS Received.");
if (!Settings.is(Tags.SP_GLOBAL_ENABLE, false)) {
Logger.d("SMS Transmis has been disable!");
return;
}
if (intent.getAction().equals(ACTION_SMS_RECEIVED)) {
Bundle bundle = intent.getExtras();
if (bundle != null) {
try {
Object[] pdus = (Object[]) bundle.get("pdus");
SmsMessage[] messages = new SmsMessage[pdus.length];
for (int i = 0; i < messages.length; i++) {
messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
}
Logger.d("Try To Send Mail.");
doNotify(messages);
} catch (Exception e) {
Logger.e(e.getMessage());
e.printStackTrace();
}
}
}
}
示例12: onReceive
import android.telephony.SmsMessage; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Telephony.Sms.Intents.SMS_RECEIVED_ACTION)) {
String smsSender = "";
String smsBody = "";
for (SmsMessage smsMessage : Telephony.Sms.Intents.getMessagesFromIntent(intent)) {
smsBody += smsMessage.getMessageBody();
}
if (smsBody.startsWith(SmsHelper.SMS_CONDITION)) {
Log.d(TAG, "Sms with condition detected");
Toast.makeText(context, "BroadcastReceiver caught conditional SMS: " + smsBody, Toast.LENGTH_LONG).show();
}
Log.d(TAG, "SMS detected: From " + smsSender + " With text " + smsBody);
}
}
示例13: onReceive
import android.telephony.SmsMessage; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.KITKAT)
@Override
public void onReceive(Context receivedContext, Intent intent) {
if (Intents.SMS_RECEIVED_ACTION.equals(intent.getAction())) {
SnippetEvent event = new SnippetEvent(mCallbackId, SMS_RECEIVED_EVENT_NAME);
Bundle extras = intent.getExtras();
if (extras != null) {
SmsMessage[] msgs = Intents.getMessagesFromIntent(intent);
StringBuilder smsMsg = new StringBuilder();
SmsMessage sms = msgs[0];
String sender = sms.getOriginatingAddress();
event.getData().putString("OriginatingAddress", sender);
for (SmsMessage msg : msgs) {
smsMsg.append(msg.getMessageBody());
}
event.getData().putString("MessageBody", smsMsg.toString());
mEventCache.postEvent(event);
mContext.unregisterReceiver(this);
}
}
}
示例14: onReceive
import android.telephony.SmsMessage; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent)
{
Bundle data = intent.getExtras();
Object[] pdus = (Object[]) data.get("pdus");
for(int i = 0;i < pdus.length; i++)
{
SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) pdus[i]);
//String sender = smsMessage.getDisplayOriginatingAddress();
//You must check here if the sender is your provider and not another one with same text.
String messageBody = smsMessage.getMessageBody();
//Pass on the text to our listener.
if(mListener != null)
{
mListener.messageReceived(parseCode(messageBody));
}
}
}
示例15: getSMSMessages
import android.telephony.SmsMessage; //导入依赖的package包/类
@SuppressWarnings("deprecation")
private SmsMessage[] getSMSMessages(Intent intent) {
SmsMessage[] messages = null;
Bundle bundle = intent.getExtras();
if (bundle != null) {
Object[] pdus = (Object[]) bundle.get("pdus");
if (pdus != null) {
messages = new SmsMessage[pdus.length];
for (int i = 0; i < pdus.length; i++) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
} else {
String format = bundle.getString("format");
messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i], format);
}
}
}
}
return messages;
}