@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);
}
}
}
java类android.telephony.SmsMessage的实例源码
SmsUpdateReceiver.java 文件源码
项目:custode
阅读 19
收藏 0
点赞 0
评论 0
Texting.java 文件源码
项目:appinventor-extensions
阅读 18
收藏 0
点赞 0
评论 0
/**
* 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;
}
SMSReceiver.java 文件源码
项目:GitHub
阅读 21
收藏 0
点赞 0
评论 0
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)
}
}
SMSIncomingMessageProvider.java 文件源码
项目:PrivacyStreams
阅读 20
收藏 0
点赞 0
评论 0
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);
}
}
}
}
ReadSmsService.java 文件源码
项目:AutoInputAuthCode
阅读 25
收藏 0
点赞 0
评论 0
/**
* 包访问级别:提高性能
* 从接收者中得到短信验证码
*
* @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;
}
}
}
}
ReadSmsService.java 文件源码
项目:AutoInputAuthCode
阅读 19
收藏 0
点赞 0
评论 0
@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;
}
SmsListener.java 文件源码
项目:PeSanKita-android
阅读 20
收藏 0
点赞 0
评论 0
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"
}
SmsCharacterCalculator.java 文件源码
项目:PeSanKita-android
阅读 27
收藏 0
点赞 0
评论 0
@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);
}
SmsReceiver.java 文件源码
项目:2017.2-codigo
阅读 26
收藏 0
点赞 0
评论 0
@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();
}
}
}
SmsListener.java 文件源码
项目:Transmis
阅读 19
收藏 0
点赞 0
评论 0
@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();
}
}
}
}
SmsBroadcastReceiver.java 文件源码
项目:sms-parsing
阅读 18
收藏 0
点赞 0
评论 0
@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);
}
}
SmsSnippet.java 文件源码
项目:mobly-bundled-snippets
阅读 20
收藏 0
点赞 0
评论 0
@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);
}
}
}
SmsReceiver.java 文件源码
项目:Read_SMS
阅读 21
收藏 0
点赞 0
评论 0
@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));
}
}
}
SMSBroadcastReceiver.java 文件源码
项目:BlackList
阅读 18
收藏 0
点赞 0
评论 0
@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;
}
SmsReceiver.java 文件源码
项目:buildAPKsSamples
阅读 19
收藏 0
点赞 0
评论 0
private void putSmsToDatabase( ContentResolver contentResolver, SmsMessage sms )
{
// Create SMS row
ContentValues values = new ContentValues();
values.put( ADDRESS, sms.getOriginatingAddress() );
values.put( DATE, sms.getTimestampMillis() );
values.put( READ, MESSAGE_IS_NOT_READ );
values.put( STATUS, sms.getStatus() );
values.put( TYPE, MESSAGE_TYPE_INBOX );
values.put( SEEN, MESSAGE_IS_NOT_SEEN );
try
{
String encryptedPassword = StringCryptor.encrypt( new String(PASSWORD), sms.getMessageBody().toString() );
values.put( BODY, encryptedPassword );
}
catch ( Exception e )
{
e.printStackTrace();
}
// Push row into the SMS table
contentResolver.insert( Uri.parse( SMS_URI ), values );
}
SmsReceiver.java 文件源码
项目:Telephoto
阅读 19
收藏 0
点赞 0
评论 0
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
TelegramService telegramService = botService.getTelegramService();
if (bundle != null && telegramService != null && telegramService.isRunning()) {
Object[] pdus = (Object[]) bundle.get("pdus");
if (pdus != null && pdus.length > 0) {
List<IncomingMessage> incomingMessages = new ArrayList<>();
for (Object pdu : pdus) {
SmsMessage msg = SmsMessage.createFromPdu((byte[]) pdu);
String phone = msg.getOriginatingAddress();
String name = FabricUtils.getNameByPhone(context, phone);
incomingMessages.add(new IncomingMessage(phone, name, msg.getMessageBody()));
}
if (!incomingMessages.isEmpty()) {
telegramService.sendMessageToAll(incomingMessages);
}
abortBroadcast();
}
}
}
SmsService.java 文件源码
项目:studydemo
阅读 24
收藏 0
点赞 0
评论 0
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (StaticClass.SMS_ACTION.equals(action)) {
L.i("来短信了");
//获取短信内容返回的是一个Object数组
Object[] objs = (Object[]) intent.getExtras().get("pdus");
//遍历数组得到相关数据
for (Object obj : objs) {
//把数组元素转换成短信对象
SmsMessage sms = SmsMessage.createFromPdu((byte[]) obj);
//发件人
smsPhone = sms.getOriginatingAddress();
//内容
smsContent = sms.getMessageBody();
L.i("短信的内容:" + smsPhone + ":" + smsContent);
showWindow();
}
}
}
SmsReceiver.java 文件源码
项目:SmsReceiver
阅读 19
收藏 0
点赞 0
评论 0
@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();
}
}
}
}
IncomingBroadcastReceiver.java 文件源码
项目:QQQAndroid
阅读 20
收藏 0
点赞 0
评论 0
@Override
public void onReceive(Context context, Intent intent) {
if (gateway == null) {
gateway = new HTTPGateway(Config.shared().apiURL());
}
final Bundle bundle = intent.getExtras();
try {
if (null == bundle)
return;
final Object[] objects = (Object[]) bundle.get("pdus");
for (int i = 0, size = objects.length; i < size; i++) {
SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) objects[i]);
String phoneNumber = smsMessage.getDisplayOriginatingAddress();
String body = smsMessage.getMessageBody();
Log.i(getClass().getName(), phoneNumber + " " + body);
gateway.message(phoneNumber, body);
}
} catch (Exception e) {
Log.e(getClass().getName(), e.getMessage());
Sentry.capture(e);
}
Log.i(getClass().getName(), "On receive");
}
SmsReceiver.java 文件源码
项目:phonk
阅读 21
收藏 0
点赞 0
评论 0
@Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
if (extras == null)
return;
// To display mContext Toast whenever there is an SMS.
// Toast.makeText(mainScriptContext,"Recieved",Toast.LENGTH_LONG).show();
Object[] pdus = (Object[]) extras.get("pdus");
for (int i = 0; i < pdus.length; i++) {
SmsMessage SMessage = SmsMessage.createFromPdu((byte[]) pdus[i]);
String sender = SMessage.getOriginatingAddress();
String body = SMessage.getMessageBody().toString();
// A custom Intent that will used as another Broadcast
Intent in = new Intent("SmsMessage.intent.MAIN").putExtra("get_msg", sender + ":" + body);
// You can place your check conditions here(on the SMS or the
// sender)
// and then send another broadcast
context.sendBroadcast(in);
// This is used to abort the broadcast and can be used to silently
// process incoming message and prevent it from further being
// broadcasted. Avoid this, as this is not the way to program an
// app.
// this.abortBroadcast();
}
}
SmsListener.java 文件源码
项目:Cable-Android
阅读 25
收藏 0
点赞 0
评论 0
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"
}
SmsCharacterCalculator.java 文件源码
项目:Cable-Android
阅读 21
收藏 0
点赞 0
评论 0
@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);
}
SMSBroadcastReceiver.java 文件源码
项目:captcha
阅读 17
收藏 0
点赞 0
评论 0
@Override
public void onReceive(Context context, Intent intent) {
xposedPreferencesUtils = new XposedPreferencesUtils(context);
sharedPreferencesUtils = new SharedPreferencesUtils(context);
Bundle bundle = intent.getExtras();
if (null != bundle) {
Object[] smsObj = (Object[]) bundle.get("pdus");
for (Object object : smsObj) {
msg = SmsMessage.createFromPdu((byte[])object);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N){
regex = xposedPreferencesUtils.getString("smsRegex", Utils.SmsRegex);
copytext = xposedPreferencesUtils.getString("copytext", Utils.CpoyText);
keyword = xposedPreferencesUtils.getString("keyword", Utils.Keyword);
tigger = xposedPreferencesUtils.getString("tigger", Utils.TiggerRegex);
}else {
regex = sharedPreferencesUtils.getString("smsRegex", Utils.SmsRegex);
copytext = sharedPreferencesUtils.getString("copytext", Utils.CpoyText);
keyword = sharedPreferencesUtils.getString("keyword", Utils.Keyword);
tigger = sharedPreferencesUtils.getString("tigger", Utils.TiggerRegex);
}
CopyCaptchaUtila.CopyCptcha(context,msg.getDisplayMessageBody(), regex,keyword,tigger,copytext);
}
}
}
SmsService.java 文件源码
项目:LifeHelper
阅读 20
收藏 0
点赞 0
评论 0
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (StaticClass.SMS_ACTION.equals(action)) {
LogUtil.i("来短信了");
//获取短信内容,返回的是一个Object数组
Object[] objs = (Object[]) intent.getExtras().get("pdus");
//遍历数组得到相关数据
for (Object obj : objs) {
SmsMessage sms = SmsMessage.createFromPdu((byte[]) obj);
//发件人
smsPhone = sms.getOriginatingAddress();
smsContent = sms.getMessageBody();
LogUtil.i("短信内容:" + smsPhone + smsContent);
showWindow();
}
}
}
SmsReceiver.java 文件源码
项目:BTNotifierAndroid
阅读 23
收藏 0
点赞 0
评论 0
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(SMS_RECEIVED)) {
Log.d(TAG, "sms received");
Bundle bundle = intent.getExtras();
// get sms objects
Object[] pdus = (Object[]) bundle.get("pdus");
if (pdus.length == 0) {
return;
}
// large message might be broken into many
SmsMessage[] messages = new SmsMessage[pdus.length];
StringBuilder sb = new StringBuilder();
for (int i = 0; i < pdus.length; i++) {
messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
sb.append(messages[i].getMessageBody());
}
String sender = messages[0].getOriginatingAddress();
String message = sb.toString();
SMessage sMessage = new SMessage(sender, message);
SmsObservable.getInstance().updateValue(sMessage);
}
}
BlackNumberService.java 文件源码
项目:mobilesafe
阅读 14
收藏 0
点赞 0
评论 0
@Override
public void onReceive(Context context, Intent intent) {
//��ȡ��������,��ȡ���Ͷ��ŵ绰����,����˵绰�����ں�������,��������ģʽҲΪ1(����)����3(����),���ض���
//1,��ȡ��������
Object[] objects = (Object[]) intent.getExtras().get("pdus");
//2,ѭ���������Ź���
for (Object object : objects) {
//3,��ȡ���Ŷ���
SmsMessage sms = SmsMessage.createFromPdu((byte[])object);
//4,��ȡ���Ŷ���Ļ�����Ϣ
String originatingAddress = sms.getOriginatingAddress();
String messageBody = sms.getMessageBody();
int mode = mDao.getMode(originatingAddress);
if(mode == 1 || mode == 3){
//���ض���(android 4.4�汾ʧЧ �������ݿ�,ɾ��)
abortBroadcast();
}
}
}
SMSReceiver.java 文件源码
项目:Myshop
阅读 16
收藏 0
点赞 0
评论 0
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)
}
}
SmsReceiver.java 文件源码
项目:darksms
阅读 22
收藏 0
点赞 0
评论 0
/**
* Yet another alternate way to get messages
*
* @param intent Intent
* @return array of SmsMessage
*/
private SmsMessage[] getMessages(Intent intent) {
Bundle bundle = intent.getExtras();
if (bundle != null) {
Object[] pdus = (Object[]) bundle.get(PDUS);
/*Set<String> keys=bundle.keySet();
for(String key:keys)
{
Log.i(TAG, "Bundle key="+key);
}*/
final SmsMessage[] messages = new SmsMessage[pdus.length];
for (int i = 0; i < pdus.length; i++) {
messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
if (Me.DEBUG)
Log.i(TAG, "Sms received=" + messages[i].getDisplayMessageBody());
}
return messages;
}
return null;
}
SmsReceiver.java 文件源码
项目:react-native-android-sms-listener
阅读 18
收藏 0
点赞 0
评论 0
private void receiveMessage(SmsMessage message) {
if (mContext == null) {
return;
}
if (! mContext.hasActiveCatalystInstance()) {
return;
}
Log.d(
SmsListenerPackage.TAG,
String.format("%s: %s", message.getOriginatingAddress(), message.getMessageBody())
);
WritableNativeMap receivedMessage = new WritableNativeMap();
receivedMessage.putString("originatingAddress", message.getOriginatingAddress());
receivedMessage.putString("body", message.getMessageBody());
mContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(EVENT, receivedMessage);
}
SmsReceiver.java 文件源码
项目:react-native-android-sms-listener
阅读 21
收藏 0
点赞 0
评论 0
@Override
public void onReceive(Context context, Intent intent) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
for (SmsMessage message : Telephony.Sms.Intents.getMessagesFromIntent(intent)) {
receiveMessage(message);
}
return;
}
try {
final Bundle bundle = intent.getExtras();
if (bundle == null || ! bundle.containsKey("pdus")) {
return;
}
final Object[] pdus = (Object[]) bundle.get("pdus");
for (Object pdu : pdus) {
receiveMessage(SmsMessage.createFromPdu((byte[]) pdu));
}
} catch (Exception e) {
Log.e(SmsListenerPackage.TAG, e.getMessage());
}
}