当前位置: 首页>>代码示例>>Java>>正文


Java SmsMessage类代码示例

本文整理汇总了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);
            }
    }
}
 
开发者ID:gvinciguerra,项目名称:custode,代码行数:21,代码来源:SmsUpdateReceiver.java

示例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;
}
 
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:27,代码来源:Texting.java

示例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);
    }
}
 
开发者ID:slvn,项目名称:android-aosp-mms,代码行数:21,代码来源:SmsReceiverService.java

示例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)
	}
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:SMSReceiver.java

示例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);
            }
        }
    }
}
 
开发者ID:PrivacyStreams,项目名称:PrivacyStreams,代码行数:24,代码来源:SMSIncomingMessageProvider.java

示例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;
            }
        }
    }
}
 
开发者ID:xiong-it,项目名称:AutoInputAuthCode,代码行数:30,代码来源:ReadSmsService.java

示例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;
}
 
开发者ID:xiong-it,项目名称:AutoInputAuthCode,代码行数:18,代码来源:ReadSmsService.java

示例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"
  }
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:17,代码来源:SmsListener.java

示例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);
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:19,代码来源:SmsCharacterCalculator.java

示例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();
        }
    }
}
 
开发者ID:if710,项目名称:2017.2-codigo,代码行数:22,代码来源:SmsReceiver.java

示例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();
            }
        }
    }
}
 
开发者ID:dss886,项目名称:Transmis,代码行数:26,代码来源:SmsListener.java

示例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);
    }
}
 
开发者ID:JoaquimLey,项目名称:sms-parsing,代码行数:17,代码来源:SmsBroadcastReceiver.java

示例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);
        }
    }
}
 
开发者ID:google,项目名称:mobly-bundled-snippets,代码行数:24,代码来源:SmsSnippet.java

示例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));
        }
    }

}
 
开发者ID:yash786agg,项目名称:Read_SMS,代码行数:26,代码来源:SmsReceiver.java

示例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;
}
 
开发者ID:kaliturin,项目名称:BlackList,代码行数:21,代码来源:SMSBroadcastReceiver.java


注:本文中的android.telephony.SmsMessage类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。