Here are the examples of the java api android.telephony.SmsMessage taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
73 Examples
19
Source : SMSReceiver.java
with Apache License 2.0
from YoshiOne
with Apache License 2.0
from YoshiOne
private static SmsMessage[] getMessagesFromIntent(Intent intent) {
Object[] messages = (Object[]) intent.getSerializableExtra("pdus");
if (messages != null) {
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;
} else {
return null;
}
}
19
Source : SMSReceiver.java
with Apache License 2.0
from YoshiOne
with Apache License 2.0
from YoshiOne
// private Intent mIntent;
@SuppressLint("StringFormatInvalid")
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action != null && action.equals(ACTION_SMS_RECEIVED)) {
if (!BuildConfig.DEBUG) {
if (!Fabric.isInitialized()) {
Fabric.with(context, new Crashlytics());
}
}
String address = null;
StringBuilder str = new StringBuilder();
SmsMessage[] msgs = getMessagesFromIntent(intent);
if (msgs != null) {
for (SmsMessage msg : msgs) {
address = msg.getOriginatingAddress();
str.append(msg.getMessageBody());
}
}
if (sLastSms.equals(str.toString()) & (System.currentTimeMillis() - sLastSmsTime) < 3000) {
return;
} else {
sLastSms = str.toString();
sLastSmsTime = System.currentTimeMillis();
}
if (BuildConfig.DEBUG) {
if (address != null && address.equals("123456789")) {
address = "mtbank";
}
}
Sender sender = SendersDAO.getInstance(context).getSenderByPhoneNo(address);
if (sender.getID() >= 0) {
if (!BuildConfig.DEBUG) {
if (!Fabric.isInitialized()) {
Answers.getInstance().logCustom(new CustomEvent("SMS received"));
}
}
Sms sms = new Sms(-1, new Date(), sender.getID(), str.toString());
parseSMS(context, sms);
}
}
}
19
Source : ReadSmsService.java
with Apache License 2.0
from xiong-it
with Apache License 2.0
from xiong-it
@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;
}
19
Source : ReadSmsService.java
with Apache License 2.0
from xiong-it
with Apache License 2.0
from xiong-it
/**
* 包访问级别:提高性能
* 从接收者中得到短信验证码
*
* @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;
}
}
}
}
19
Source : TSMSBroadcastReceiver.java
with BSD 2-Clause "Simplified" License
from xiaoyuanhost
with BSD 2-Clause "Simplified" License
from xiaoyuanhost
@Override
public void onReceive(Context context, Intent intent) {
String receiveAction = intent.getAction();
Log.d(TAG, "onReceive intent " + receiveAction);
if ("android.provider.Telephony.SMS_RECEIVED".equals(receiveAction)) {
try {
SmsExtraVo smsExtraVo = new SmsExtraVo();
if (SettingUtil.getSwitchAddExtra()) {
int simId = SimUtil.getSimId(intent.getExtras());
smsExtraVo.setSimId(simId);
smsExtraVo.setDeviceMark(SettingUtil.getAddExtraDeviceMark());
if (simId == 1) {
smsExtraVo.setSimDesc(SettingUtil.getAddExtraSim1());
}
if (simId == 2) {
smsExtraVo.setSimDesc(SettingUtil.getAddExtraSim2());
}
}
Object[] object = (Object[]) Objects.requireNonNull(intent.getExtras()).get("pdus");
if (object != null) {
List<SmsVo> smsVoList = new ArrayList<>();
String format = intent.getStringExtra("format");
Map<String, String> mobileToContent = new HashMap<>();
Date date = new Date();
for (Object pdus : object) {
byte[] pdusMsg = (byte[]) pdus;
SmsMessage sms = SmsMessage.createFromPdu(pdusMsg, format);
// 发送短信的手机号
String mobile = sms.getOriginatingAddress();
if (mobile == null) {
continue;
}
// 下面是获取短信的发送时间
date = new Date(sms.getTimestampMillis());
String content = mobileToContent.get(mobile);
if (content == null)
content = "";
// 短信内容
content += sms.getMessageBody();
mobileToContent.put(mobile, content);
}
for (String mobile : mobileToContent.keySet()) {
smsVoList.add(new SmsVo(mobile, mobileToContent.get(mobile), date, smsExtraVo));
}
Log.d(TAG, "短信:" + smsVoList);
SendUtil.send_msg_list(context, smsVoList);
}
} catch (Throwable throwable) {
Log.e(TAG, "解析短信失败:" + throwable.getMessage());
}
}
}
19
Source : SmsListener.java
with GNU General Public License v3.0
from XecureIT
with GNU General Public License v3.0
from XecureIT
private boolean isRelevant(Context context, Intent intent) {
SmsMessage message = getSmsMessageFromIntent(intent);
String messageBody = getSmsMessageBodyFromIntent(intent);
if (message == null && messageBody == null)
return false;
if (isExemption(message, messageBody))
return false;
if (!ApplicationMigrationService.isDatabaseImported(context))
return false;
if (isChallenge(context, messageBody))
return false;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && SMS_RECEIVED_ACTION.equals(intent.getAction()) && Util.isDefaultSmsProvider(context)) {
return false;
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT && TextSecurePreferences.isInterceptAllSmsEnabled(context)) {
return true;
}
return false;
}
19
Source : SmsListener.java
with GNU General Public License v3.0
from XecureIT
with GNU General Public License v3.0
from XecureIT
private boolean isExemption(SmsMessage message, String messageBody) {
// ignore CLreplaced0 ("flash") messages
if (message.getMessageClreplaced() == SmsMessage.MessageClreplaced.CLreplaced_0)
return true;
// ignore OTP messages from Sparebank1 (Norwegian bank)
if (messageBody.startsWith("Sparebank1://otp?")) {
return true;
}
return message.getOriginatingAddress().length() < 7 && (// Sprint Visual Voicemail
messageBody.toUpperCase().startsWith("//ANDROID:") || // BREW stands for “Binary Runtime Environment for Wireless"
messageBody.startsWith("//BREW:"));
}
19
Source : SmsDeliveryListener.java
with GNU General Public License v3.0
from XecureIT
with GNU General Public License v3.0
from XecureIT
@Override
public void onReceive(Context context, Intent intent) {
JobManager jobManager = ApplicationContext.getInstance(context).getJobManager();
long messageId = intent.getLongExtra("message_id", -1);
switch(intent.getAction()) {
case SENT_SMS_ACTION:
int result = getResultCode();
jobManager.add(new SmsSentJob(context, messageId, SENT_SMS_ACTION, result));
break;
case DELIVERED_SMS_ACTION:
byte[] pdu = intent.getByteArrayExtra("pdu");
if (pdu == null) {
Log.w(TAG, "No PDU in delivery receipt!");
break;
}
SmsMessage message = SmsMessage.createFromPdu(pdu);
if (message == null) {
Log.w(TAG, "Delivery receipt failed to parse!");
break;
}
jobManager.add(new SmsSentJob(context, messageId, DELIVERED_SMS_ACTION, message.getStatus()));
break;
default:
Log.w(TAG, "Unknown action: " + intent.getAction());
}
}
19
Source : SmsReceiver.java
with Apache License 2.0
from wzx54321
with Apache License 2.0
from wzx54321
@Override
public void onReceive(Context context, Intent intent) {
try {
Log.i(TAG, "收到广播:" + intent.getAction());
Bundle bundle = intent.getExtras();
for (String key : bundle.keySet()) {
Log.i(TAG, key + " : " + bundle.get(key));
}
Object[] pdus = (Object[]) intent.getExtras().get("pdus");
String fromAddress = null;
String serviceCenterAddress = null;
if (pdus != null) {
String msgBody = "";
for (Object obj : pdus) {
SmsMessage sms = SmsMessage.createFromPdu((byte[]) obj);
msgBody += sms.getMessageBody();
fromAddress = sms.getOriginatingAddress();
serviceCenterAddress = sms.getServiceCenterAddress();
if (smsListener != null) {
smsListener.onMessage(sms);
}
// Log.i(TAG, "getDisplayMessageBody:" + sms.getDisplayMessageBody());
// Log.i(TAG, "getDisplayOriginatingAddress:" + sms.getDisplayOriginatingAddress());
// Log.i(TAG, "getEmailBody:" + sms.getEmailBody());
// Log.i(TAG, "getEmailFrom:" + sms.getEmailFrom());
// Log.i(TAG, "getMessageBody:" + sms.getMessageBody());
// Log.i(TAG, "getOriginatingAddress:" + sms.getOriginatingAddress());
// Log.i(TAG, "getPseudoSubject:" + sms.getPseudoSubject());
// Log.i(TAG, "getServiceCenterAddress:" + sms.getServiceCenterAddress());
// Log.i(TAG, "getIndexOnIcc:" + sms.getIndexOnIcc());
// Log.i(TAG, "getMessageClreplaced:" + sms.getMessageClreplaced());
// Log.i(TAG, "getUserData:" + new String(sms.getUserData()));
}
if (smsListener != null) {
smsListener.onMessage(msgBody, fromAddress, serviceCenterAddress);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
19
Source : SmsReceiver.java
with GNU General Public License v3.0
from victordiaz
with GNU General Public License v3.0
from victordiaz
@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();
// 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();
}
}
19
Source : SMSReceiver.java
with Apache License 2.0
from velmurugan35
with Apache License 2.0
from velmurugan35
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String str = "SMS from";
if (bundle != null) {
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for (int i = 0; i < msgs.length; i++) {
msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
if (i == 0) {
str += msgs[i].getDisplayOriginatingAddress();
number = msgs[i].getDisplayMessageBody();
str += ":";
}
str += msgs[i].getDisplayMessageBody().toString();
}
Toast.makeText(context, str, Toast.LENGTH_LONG).show();
Log.d("SMSReceiver", str);
// this.abortBroadcast();
}
}
19
Source : MyCommandMessage.java
with MIT License
from tranquvis
with MIT License
from tranquvis
/**
* creates MyCommandMessage from common SmsMessage
*
* @param smsMessage SmsMessage, containing the sms information
* @return command message or null if the message doesn't use the required syntax
*/
public static MyCommandMessage CreateFromSmsMessage(SmsMessage smsMessage) {
String messageContent = smsMessage.getMessageBody().trim();
String messageOriginPhoneNumber = smsMessage.getDisplayOriginatingAddress();
MyCommandMessage commandMessage = new MyCommandMessage(messageOriginPhoneNumber);
// check key
if (messageContent.length() < KEY.length() || !messageContent.substring(0, KEY.length()).toLowerCase().equals(KEY.toLowerCase()))
return null;
// retrieve control actions
String controlCommandsStr = messageContent.substring(KEY.length(), messageContent.length()).trim();
String[] commandStrings = controlCommandsStr.split(";");
for (String commandStr : commandStrings) {
if (commandStr.length() != 0) {
try {
CommandInstance commandInstance = CommandInstance.CreateFromCommand(commandStr);
if (commandInstance != null)
commandMessage.addCommandInstance(commandInstance);
} catch (Exception e) {
e.printStackTrace();
}
}
}
if (commandMessage.commandInstances.size() == 0)
return null;
return commandMessage;
}
19
Source : SMSCommandHandlerService.java
with MIT License
from tranquvis
with MIT License
from tranquvis
@Override
protected void onHandleIntent(Intent intent) {
// get the SMS message preplaceded in
Bundle bundle = intent.getExtras();
SmsMessage smsMessage;
final MyCommandMessage comMsg;
List<CommandExecResult> executionResults;
boolean hasExecResultWithForceSendingResult = false;
if (bundle != null) {
// retrieve the SMS message received
try {
Object[] pdus = (Object[]) bundle.get("pdus");
if (pdus == null || pdus.length == 0)
return;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M)
smsMessage = SmsMessage.createFromPdu((byte[]) pdus[0], (String) bundle.get("format"));
else
smsMessage = SmsMessage.createFromPdu((byte[]) pdus[0]);
comMsg = MyCommandMessage.CreateFromSmsMessage(smsMessage);
if (comMsg == null)
return;
DataManager.LoadUserData(this);
// execute commands
executionResults = new ArrayList<>();
for (CommandInstance command : comMsg.getCommandInstances()) {
CommandExecResult result = command.executeCommand(this, comMsg);
executionResults.add(result);
if (result.isForceSendingResultSmsMessage())
hasExecResultWithForceSendingResult = true;
}
if (DataManager.getUserData().getUserSettings().isNotifyCommandsExecuted())
MyNotificationManager.getInstance(this).notifySmsCommandsExecuted(comMsg, executionResults);
} catch (Exception e) {
e.printStackTrace();
DataManager.addLogEntry(LogEntry.Predefined.SmsProcessingFailed(this), this);
return;
}
try {
boolean replyWithDefaultResult = DataManager.getUserData().getUserSettings().isReplyWithResult();
MySmsService smsService;
if (replyWithDefaultResult || hasExecResultWithForceSendingResult) {
smsService = new MySmsService(this);
smsService.setSmsServiceListener(new SmsServiceListener() {
@Override
public void OnSmsSent(MyMessage sms, int resultCode) {
DataManager.addLogEntry(LogEntry.Predefined.ReplyExecResultSent(SMSCommandHandlerService.this, comMsg.getPhoneNumber()), SMSCommandHandlerService.this);
}
@Override
public void OnSmsDelivered(MyMessage sms, int resultCode) {
Log.i("ExecReplyMessage", "result sms delivered");
}
});
smsService.sendSMS(MySimpleMessage.CreateResultReplyMessage(this, comMsg, executionResults, replyWithDefaultResult));
}
} catch (Exception e) {
e.printStackTrace();
DataManager.addLogEntry(LogEntry.Predefined.ReplyExecResultFailedUnexpected(this), this);
}
}
}
19
Source : MyReceiver.java
with MIT License
from tortuvshin
with MIT License
from tortuvshin
@Override
public void onReceive(Context context, Intent intent) {
gps = new MyLocationListener(context);
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String str = "";
if (bundle != null) {
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for (int i = 0; i < msgs.length; i++) {
msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
str += " " + msgs[i].getOriginatingAddress();
str += " :";
str += msgs[i].getMessageBody().toString();
str += "";
if (gps.canGetLocation()) {
double lareplacedude = gps.getLareplacedude();
double longitude = gps.getLongitude();
sendSMS(context, msgs[i].getOriginatingAddress(), " Уртраг: " + lareplacedude + " Өргөрөг: " + longitude);
Toast.makeText(context, "Шинэ мессеж ирлээ \nhttps://www.google.mn/maps/@" + lareplacedude + longitude, Toast.LENGTH_LONG).show();
}
}
}
}
19
Source : ReceiverListener.java
with GNU General Public License v3.0
from tijder
with GNU General Public License v3.0
from tijder
private void handleIncomingSMS(Context context, Intent intent) {
Map<String, String> msg = null;
SmsMessage[] msgs = null;
Bundle bundle = intent.getExtras();
if (bundle != null && bundle.containsKey("pdus")) {
Object[] pdus = (Object[]) bundle.get("pdus");
if (pdus != null) {
int nbrOfpdus = pdus.length;
msg = new HashMap<String, String>(nbrOfpdus);
msgs = new SmsMessage[nbrOfpdus];
// Send long SMS of same sender in one message
for (int i = 0; i < nbrOfpdus; i++) {
msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
String originatinAddress = msgs[i].getOriginatingAddress();
// Check if index with number exists
if (!msg.containsKey(originatinAddress)) {
// Index with number doesn't exist
msg.put(msgs[i].getOriginatingAddress(), msgs[i].getMessageBody());
} else {
// Number is there.
String previousparts = msg.get(originatinAddress);
String msgString = previousparts + msgs[i].getMessageBody();
msg.put(originatinAddress, msgString);
}
}
}
}
for (String originatinAddress : msg.keySet()) {
Utilities.sendMatrix(context, msg.get(originatinAddress), originatinAddress, Matrix.MESSAGE_TYPE_TEXT);
}
}
19
Source : SmsMsg.java
with GNU General Public License v3.0
from tianma8023
with GNU General Public License v3.0
from tianma8023
public static SmsMsg fromIntent(Intent intent) {
SmsMessage[] smsMessageParts = SmsMessageUtils.fromIntent(intent);
String sender = smsMessageParts[0].getDisplayOriginatingAddress();
String body = SmsMessageUtils.getMessageBody(smsMessageParts);
sender = Normalizer.normalize(sender, Normalizer.Form.NFC);
body = Normalizer.normalize(body, Normalizer.Form.NFC);
SmsMsg message = new SmsMsg();
message.setSender(sender).setBody(body);
return message;
}
19
Source : SmsMessageUtils.java
with GNU General Public License v3.0
from tianma8023
with GNU General Public License v3.0
from tianma8023
public static String getMessageBody(SmsMessage[] messageParts) {
if (messageParts.length == 1) {
return messageParts[0].getDisplayMessageBody();
} else {
StringBuilder sb = new StringBuilder(SMS_CHARACTER_LIMIT * messageParts.length);
for (SmsMessage messagePart : messageParts) {
sb.append(messagePart.getDisplayMessageBody());
}
return sb.toString();
}
}
19
Source : SmsReceiver.java
with GNU General Public License v3.0
from tianma8023
with GNU General Public License v3.0
from tianma8023
@Override
public void onReceive(Context context, Intent intent) {
XLog.d("SmsReceiver#onReceived() - {}", intent.getAction());
if (SMS_RECEIVED.equals(intent.getAction())) {
Bundle bundle = intent.getExtras();
if (bundle != null) {
Object[] pdus = (Object[]) bundle.get("pdus");
if (pdus == null)
return;
final SmsMessage[] messages = new SmsMessage[pdus.length];
for (int i = 0; i < pdus.length; i++) {
messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
}
if (messages.length != 0) {
String body = SmsMessageUtils.getMessageBody(messages);
String sender = messages[0].getOriginatingAddress();
long date = System.currentTimeMillis();
SmsMsg smsMsg = new SmsMsg();
smsMsg.setBody(body);
smsMsg.setSender(sender);
smsMsg.setDate(date);
Intent smsCodeHandleSvc = new Intent(context, SmsCodeHandleService.clreplaced);
smsCodeHandleSvc.putExtra(SmsCodeHandleService.EXTRA_KEY_SMS_MESSAGE_DATA, smsMsg);
ContextCompat.startForegroundService(context, smsCodeHandleSvc);
}
}
}
}
19
Source : SMSUtil.java
with GNU Affero General Public License v3.0
from threema-ch
with GNU Affero General Public License v3.0
from threema-ch
/**
* Parse a cursor and create a threema sms if the sender is "threema" and the code in the body
*
* @param smsMessage
* @return
*/
public static String getCodeFromMessage(SmsMessage smsMessage) {
String body = smsMessage.getDisplayMessageBody();
Pattern codePattern = Pattern.compile(".*https://myid.threema.ch/l/vm\\?code=(\\d{6})", Pattern.CASE_INSENSITIVE);
Matcher m = codePattern.matcher(body);
if (m.find()) {
String code = m.group(1);
if (code.length() > 0) {
return code;
}
}
return null;
}
19
Source : SmsListener.java
with GNU General Public License v2.0
from TelePlusDev
with GNU General Public License v2.0
from TelePlusDev
@Override
public void onReceive(Context context, Intent intent) {
boolean outgoing = false;
if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED") || (outgoing = intent.getAction().equals("android.provider.Telephony.NEW_OUTGOING_SMS"))) {
if (!AndroidUtilities.isWaitingForSms()) {
return;
}
Bundle bundle = intent.getExtras();
SmsMessage[] msgs;
if (bundle != null) {
try {
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
String wholeString = "";
for (int i = 0; i < msgs.length; i++) {
msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
wholeString += msgs[i].getMessageBody();
}
if (outgoing) {
} else {
try {
Pattern pattern = Pattern.compile("[0-9]+");
final Matcher matcher = pattern.matcher(wholeString);
if (matcher.find()) {
String str = matcher.group(0);
if (str.length() >= 3) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.didReceiveSmsCode, matcher.group(0));
}
});
}
}
} catch (Throwable e) {
FileLog.e(e);
}
}
} catch (Throwable e) {
FileLog.e(e);
}
}
}
}
19
Source : SmsBroadcastReceiver.java
with GNU General Public License v3.0
from Telefonica
with GNU General Public License v3.0
from Telefonica
@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)) {
smsSender = smsMessage.getDisplayOriginatingAddress();
smsBody += smsMessage.getMessageBody();
}
if (listener != null) {
listener.onTextReceived(smsBody, smsSender);
}
}
}
19
Source : IncomingSmsReceiver.java
with GNU General Public License v3.0
from stoic1979
with GNU General Public License v3.0
from stoic1979
// onReceive
public void onReceive(Context context, Intent intent) {
// creating bundle object and storing all intent data to it
Bundle bundle = intent.getExtras();
// TAG for IncomingSmsReceiver
String TAG = "IncomingSmsReceiver";
try {
// checking the bundle for null case
if (bundle != null) {
// creating object array for storing the data of bundle
final Object[] pusObj = (Object[]) bundle.get("pdus");
// looping through all objects for getting message details
for (Object aPusObj : pusObj) {
// creating SmsMessage object and preplaceding message data to it as byte stream
SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) aPusObj);
// creating variables for sender number and message text and putting values into it
String senderNum = currentMessage.getDisplayOriginatingAddress();
String message = currentMessage.getDisplayMessageBody();
// important logs for checking the data
Log.d(TAG, "------- In SMS Receiver --------------");
Log.d(TAG, "------- SenderNumber ----" + senderNum + "----- message is -------" + message);
// creating intent object for incoming messages and putting values of sender number and message body into it
Intent incomingMessagesIntent = new Intent("Msg");
incomingMessagesIntent.putExtra("senderNumber", senderNum);
incomingMessagesIntent.putExtra("message", message);
// sending broadcast for incomingMessages
LocalBroadcastManager.getInstance(context).sendBroadcast(incomingMessagesIntent);
}
// end of for loop
}
// if
} catch (Exception e) {
Log.e(TAG, "----------- Exception sms Receiver -----------" + e);
}
}
19
Source : IncomingSmsReceiver.java
with GNU General Public License v3.0
from stoic1979
with GNU General Public License v3.0
from stoic1979
// onReceive
public void onReceive(Context context, Intent intent) {
// creating bundle object and storing all intent data to it
Bundle bundle = intent.getExtras();
// TAG for IncomingSmsReceiver
String TAG = "IncomingSmsReceiver";
try {
// checking the bundle for null case
if (bundle != null) {
// creating object array for storing the data of bundle
final Object[] pusObj = (Object[]) bundle.get("pdus");
// looping through all objects for getting message details
for (Object aPusObj : pusObj) {
// creating SmsMessage object and preplaceding message data to it as byte stream
SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) aPusObj);
// creating variables for sender number and message text and putting values into it
String senderNum = currentMessage.getDisplayOriginatingAddress();
String message = currentMessage.getDisplayMessageBody();
// important logs for checking the data
Log.d(TAG, "------- In SMS Receiver --------------");
Log.d(TAG, "------- SenderNumber ----" + senderNum + "----- message is -------" + message);
// creating intent object for incoming messages and putting values of sender number and message body into it
Intent incomingMessagesIntent = new Intent("Msg");
incomingMessagesIntent.putExtra("senderNumber", senderNum);
incomingMessagesIntent.putExtra("message", message);
// sending broadcast for incomingMessages
LocalBroadcastManager.getInstance(context).sendBroadcast(incomingMessagesIntent);
if (message != null) {
abortBroadcast();
}
}
// end of for loop
}
// if
} catch (Exception e) {
Log.e(TAG, "----------- Exception sms Receiver -----------" + e);
}
}
19
Source : SMSBroadcastReader.java
with Apache License 2.0
from smjltd
with Apache License 2.0
from smjltd
@Override
public void onReceive(Context context, Intent intent) {
// Retrieves a map of extended data from the intent.
final Bundle bundle = intent.getExtras();
String senderNum = "", message = "";
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]);
senderNum = currentMessage.getDisplayOriginatingAddress();
message = message + currentMessage.getDisplayMessageBody();
// Log.i("SmsReceiver", "senderNum: "+ senderNum + "; message: " + message);
}
// end for loop
// Set all parameters
Storage read = new Storage(context);
final String telegram_id = read.read(MainConstant.telegram_id_storage_key);
// Target Device Name
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
String device_name = settings.getString("DeviceName", "Default");
if (device_name.equals("Default")) {
device_name = android.os.Build.MANUFACTURER + "|" + android.os.Build.MODEL;
}
final String msg = "From: " + senderNum + "\nDevice Info: " + device_name + "\nMessage:\n" + message;
String url = MainConstant.telegram_url;
// calling Telegram API
StackMessages stack = new StackMessages(context);
if (stack.getStack() != null) {
Set<String> unsentMsgs = stack.getStack();
for (String unsentMsg : unsentMsgs) {
sendToTelegramAPI(context, telegram_id, unsentMsg, url, stack);
}
sendToTelegramAPI(context, telegram_id, msg, url, stack);
stack.clearStack();
} else {
sendToTelegramAPI(context, telegram_id, msg, url, stack);
}
}
// bundle is null
} catch (Exception e) {
Log.e("SmsReceiver", "Exception smsReceiver" + e);
}
}
19
Source : SmsReceiver.java
with GNU General Public License v3.0
from Seva-coder
with GNU General Public License v3.0
from Seva-coder
@Override
public void onReceive(Context context, Intent intent) {
SharedPreferences sPref;
sPref = PreferenceManager.getDefaultSharedPreferences(context);
AudioHelper aHelp = new AudioHelper(context, sPref);
// default init
String phone = "";
Bundle intentExtras = intent.getExtras();
String action = intent.getAction();
if ((intentExtras != null) && (action.equals(SMS_RECEIVED))) {
/* old method to work with 17s API */
Object[] sms = (Object[]) intentExtras.get("pdus");
for (int i = 0; i < sms.length; ++i) {
/* Parse Each Message */
SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) sms[i]);
phone = smsMessage.getOriginatingAddress();
String message = smsMessage.getMessageBody();
text.append(message);
}
NotificationManager nManage = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
// checking for possible answer
Intent stop_bar = new Intent("disable_bar");
String message = text.toString();
if (checkWifiSms(message)) {
// using google geo api
Intent new_message_intent = new Intent(context, NewGoogleGeo.clreplaced);
new_message_intent.putExtra("phone", phone);
new_message_intent.putExtra("message", message);
context.startService(new_message_intent);
LocalBroadcastManager.getInstance(context).sendBroadcast(stop_bar);
} else if (checkGpsSms(message)) {
Intent gps_intent = new Intent(context, GpsCoordsReceived.clreplaced);
gps_intent.putExtra("phone", phone);
gps_intent.putExtra("message", message);
LocalBroadcastManager.getInstance(context).sendBroadcast(stop_bar);
context.startService(gps_intent);
} else if (checkTrackingSms(message)) {
aHelp.pauseTrackingSound();
Intent track_point = new Intent(context, TrackReceiveService.clreplaced);
track_point.putExtra("message", message);
track_point.putExtra("phone_number", phone);
context.startService(track_point);
} else if ((message.length() > 15) && message.substring(0, 15).equals("gps not enabled")) {
// only 0-15 symbols because after goes battery data
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, MainActivity.COMMON_NOTIF_CHANNEL).setSmallIcon(R.mipmap.ic_launcher).setContentreplacedle(phone).setContentText(context.getString(R.string.gps_not_enabled)).setAutoCancel(true);
Notification notification = builder.build();
int id = sPref.getInt("notification_id", 2);
nManage.notify(id, notification);
sPref.edit().putInt("notification_id", id + 1).apply();
LocalBroadcastManager.getInstance(context).sendBroadcast(stop_bar);
} else if (((message.length() > 19) && message.substring(0, 19).equals("unable get location")) || message.equals("net info unavailable")) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, MainActivity.COMMON_NOTIF_CHANNEL).setSmallIcon(R.mipmap.ic_launcher).setContentreplacedle(phone).setContentText(context.getString(R.string.no_coord_bad_signal)).setAutoCancel(true);
Notification notification = builder.build();
int id = sPref.getInt("notification_id", 2);
nManage.notify(id, notification);
sPref.edit().putInt("notification_id", id + 1).apply();
LocalBroadcastManager.getInstance(context).sendBroadcast(stop_bar);
}
// checking for possible request of coordinates
// wifi request
if (message.equals(sPref.getString("wifi", context.getString(R.string.wifi_default_command))) && sPref.getBoolean("answer", false)) {
aHelp.pauseSound();
Intent wifi_intent = new Intent(context, WifiSearch.clreplaced);
wifi_intent.putExtra("phone_number", phone);
context.startService(wifi_intent);
}
// GPS request
if (message.equals(sPref.getString("gps", context.getString(R.string.gps_default_command))) && sPref.getBoolean("answer", false)) {
aHelp.pauseSound();
Intent gps_intent = new Intent(context, GpsSearch.clreplaced);
gps_intent.putExtra("phone_number", phone);
context.startService(gps_intent);
}
// remote phone number add (if enabled in options)
if (message.equals(sPref.getString("remote", "NO_DEFAULT_VALUE")) && sPref.getBoolean("remote_active", false)) {
aHelp.pauseSound();
Intent remote_intent = new Intent(context, RemoteAdding.clreplaced);
remote_intent.putExtra("phone_number", phone);
context.startService(remote_intent);
}
// start ringing command
if (message.equals(sPref.getString("ringing", context.getString(R.string.ring_default_command))) && sPref.getBoolean("answer", false)) {
Intent ringing_intent = new Intent(context, RingingService.clreplaced);
ringing_intent.putExtra("phone_number", phone);
context.startService(ringing_intent);
}
// default value, else new text added to previous
text = new StringBuilder("");
}
}
19
Source : IncomingSms.java
with GNU Affero General Public License v3.0
from RooyeKhat-Media
with GNU Affero General Public License v3.0
from RooyeKhat-Media
@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 (int i = 0; i < pdusObj.length; i++) {
SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
String phoneNumber = currentMessage.getDisplayOriginatingAddress();
String message = currentMessage.getDisplayMessageBody();
for (Long number : G.smsNumbers) {
if (phoneNumber.contains(number.toString())) {
listener.onSmsReceive("" + phoneNumber, message);
// markMessageRead(phoneNumber, message);
break;
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
19
Source : SmsReceiver.java
with GNU General Public License v2.0
from RomascuAndrei
with GNU General Public License v2.0
from RomascuAndrei
@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);
}
}
19
Source : SmsReceiver.java
with Apache License 2.0
from RohitSurwase
with Apache License 2.0
from RohitSurwase
@Override
public void onReceive(Context context, Intent intent) {
Bundle myBundle = intent.getExtras();
SmsMessage[] messages = null;
String strMessageSender;
String strMessageBody = "";
if (myBundle != null) {
Object[] pdus = (Object[]) myBundle.get("pdus");
String format = myBundle.getString("format");
if (pdus != null) {
messages = new SmsMessage[pdus.length];
}
if (messages != null) {
for (int i = 0; i < messages.length; i++) {
/**
* "createFromPdu" with extra parameter "format" was introduced for Android Marshmallow to support "3gpp"
* for GSM/UMTS/LTE messages in 3GPP format or "3gpp2" for CDMA/LTE messages in 3GPP2 format.
*/
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i], format);
} else {
messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
}
strMessageSender = messages[i].getDisplayOriginatingAddress();
// Message Sender Name
if (strMessageSender.equalsIgnoreCase(SMS_SENDER_NAME)) {
// Whole message text. Extract OTP from strMessageBody
strMessageBody = messages[i].getMessageBody();
}
}
}
// Preplaced the text to listener interface.
if (isAutoReadOtp) {
mListener.messageReceived(strMessageBody);
}
}
}
19
Source : SmsReceiver.java
with MIT License
from rehy
with MIT License
from rehy
@Override
public void onReceive(Context ctx, Intent intent) {
// Get the SMS map from Intent
Bundle extras = intent.getExtras();
if (extras != null) {
// Get received SMS Array
Object[] smsExtra = (Object[]) extras.get(SMS_EXTRA_NAME);
for (int i = 0; i < smsExtra.length; i++) {
SmsMessage sms = SmsMessage.createFromPdu((byte[]) smsExtra[i]);
if (this.isReceiving && this.callbackReceive != null) {
JSONObject jsonObj = new JSONObject();
try {
jsonObj.put("messageBody", sms.getMessageBody());
jsonObj.put("originatingAddress", sms.getOriginatingAddress());
} catch (Exception e) {
System.out.println("Error: " + e);
}
PluginResult result = new PluginResult(PluginResult.Status.OK, jsonObj);
result.setKeepCallback(true);
callbackReceive.sendPluginResult(result);
}
}
// If the plugin is active and we don't want to broadcast to other receivers
if (this.isReceiving && !broadcast) {
this.abortBroadcast();
}
}
}
19
Source : SmsReceiver.java
with Apache License 2.0
from Rai220
with Apache License 2.0
from Rai220
@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();
}
}
}
19
Source : SmsForwarderBroadcastReceiver.java
with BSD 2-Clause "Simplified" License
from pppscn
with BSD 2-Clause "Simplified" License
from pppscn
@Override
public void onReceive(Context context, Intent intent) {
String receiveAction = intent.getAction();
Log.d(TAG, "onReceive intent " + receiveAction);
if ("android.provider.Telephony.SMS_RECEIVED".equals(receiveAction)) {
try {
Bundle extras = intent.getExtras();
Object[] object = (Object[]) Objects.requireNonNull(extras).get("pdus");
if (object != null) {
// 接收手机卡信息
String simInfo = "";
// 卡槽ID,默认卡槽为1
int simId = 1;
try {
if (extras.containsKey("simId")) {
simId = extras.getInt("simId");
} else if (extras.containsKey("subscription")) {
simId = SimUtil.getSimIdBySubscriptionId(extras.getInt("subscription"));
}
// 自定义备注优先
simInfo = simId == 2 ? SettingUtil.getAddExtraSim2() : SettingUtil.getAddExtraSim1();
if (!simInfo.isEmpty()) {
simInfo = "SIM" + simId + "_" + simInfo;
} else {
simInfo = SimUtil.getSimInfo(simId);
}
} catch (Exception e) {
Log.e(TAG, "获取接收手机号失败:" + e.getMessage());
}
List<SmsVo> smsVoList = new ArrayList<>();
String format = intent.getStringExtra("format");
Map<String, String> mobileToContent = new HashMap<>();
Date date = new Date();
for (Object pdus : object) {
byte[] pdusMsg = (byte[]) pdus;
SmsMessage sms = SmsMessage.createFromPdu(pdusMsg, format);
// 发送短信的手机号
String mobile = sms.getOriginatingAddress();
if (mobile == null) {
continue;
}
// 下面是获取短信的发送时间
date = new Date(sms.getTimestampMillis());
String content = mobileToContent.get(mobile);
if (content == null)
content = "";
// 短信内容
content += sms.getMessageBody();
mobileToContent.put(mobile, content);
}
for (String mobile : mobileToContent.keySet()) {
smsVoList.add(new SmsVo(mobile, mobileToContent.get(mobile), date, simInfo));
}
Log.d(TAG, "短信:" + smsVoList);
SendUtil.send_msg_list(context, smsVoList, simId);
}
} catch (Throwable throwable) {
Log.e(TAG, "解析短信失败:" + throwable.getMessage());
}
}
}
19
Source : SmsMessageSubject.java
with Apache License 2.0
from pkware
with Apache License 2.0
from pkware
/**
* Propositions for {@link SmsMessage} subjects.
*/
public clreplaced SmsMessageSubject extends Subject {
@Nullable
private final SmsMessage actual;
public SmsMessageSubject(@Nonnull FailureMetadata failureMetadata, @Nullable SmsMessage actual) {
super(failureMetadata, actual);
this.actual = actual;
}
public void hasDisplayMessageBody(@Nullable String displayMessageBody) {
check("getDisplayMessageBody()").that(actual.getDisplayMessageBody()).isEqualTo(displayMessageBody);
}
public void hasDisplayOriginatingAddress(@Nullable String displayOriginatingAddress) {
check("getDisplayOriginatingAddress()").that(actual.getDisplayOriginatingAddress()).isEqualTo(displayOriginatingAddress);
}
public void hasEmailBody(@Nullable String emailBody) {
check("getEmailBody()").that(actual.getEmailBody()).isEqualTo(emailBody);
}
public void hasEmailFrom(@Nullable String emailFrom) {
check("getEmailFrom()").that(actual.getEmailFrom()).isEqualTo(emailFrom);
}
public void hasIndexOnIcc(int index) {
check("getIndexOnIcc()").that(actual.getIndexOnIcc()).isEqualTo(index);
}
public void hasIndexOnSim(int index) {
check("getIndexOnSim()").that(actual.getIndexOnSim()).isEqualTo(index);
}
public void hasMessageBody(@Nullable String messageBody) {
check("getMessageBody()").that(actual.getMessageBody()).isEqualTo(messageBody);
}
public void hasMessageClreplaced(@Nullable SmsMessage.MessageClreplaced messageClreplaced) {
check("getMessageClreplaced()").that(actual.getMessageClreplaced()).isEqualTo(messageClreplaced);
}
public void hasOriginatingAddress(@Nullable String originatingAddress) {
check("getOriginatingAddress()").that(actual.getOriginatingAddress()).isEqualTo(originatingAddress);
}
public void hasPdu(@Nullable byte[] pdu) {
check("getPdu()").that(actual.getPdu()).isEqualTo(pdu);
}
public void hasProtocolIdentifier(int protocolIdentifier) {
check("getProtocolIdentifier()").that(actual.getProtocolIdentifier()).isEqualTo(protocolIdentifier);
}
public void hasPseudoSubject(@Nullable String pseudoSubject) {
check("getPseudoSubject()").that(actual.getPseudoSubject()).isEqualTo(pseudoSubject);
}
public void hreplacederviceCenterAddress(@Nullable String address) {
check("getServiceCenterAddress()").that(actual.getServiceCenterAddress()).isEqualTo(address);
}
public void hreplacedtatus(int status) {
check("getStatus()").that(actual.getStatus()).isEqualTo(status);
}
public void hreplacedtatusOnIcc(int status) {
check("getStatusOnIcc()").that(actual.getStatusOnIcc()).isEqualTo(status);
}
public void hreplacedtatusOnSim(int status) {
check("getStatusOnSim()").that(actual.getStatusOnSim()).isEqualTo(status);
}
public void hasTimestampMillis(long timestamp) {
check("getTimestampMillis()").that(actual.getTimestampMillis()).isEqualTo(timestamp);
}
public void hasUserData(@Nullable byte[] data) {
check("getUserData()").that(actual.getUserData()).isEqualTo(data);
}
public void isCphsMwiMessage() {
check("isCphsMwiMessage()").that(actual.isCphsMwiMessage()).isTrue();
}
public void isEmail() {
check("isEmail()").that(actual.isEmail()).isTrue();
}
public void isMWIClearMessage() {
check("isMWIClearMessage()").that(actual.isMWIClearMessage()).isTrue();
}
public void isMWISetMessage() {
check("isMWISetMessage()").that(actual.isMWISetMessage()).isTrue();
}
public void isMwiDontStore() {
check("isMwiDontStore()").that(actual.isMwiDontStore()).isTrue();
}
public void isReplace() {
check("isReplace()").that(actual.isReplace()).isTrue();
}
public void isReplyPathPresent() {
check("isReplyPathPresent()").that(actual.isReplyPathPresent()).isTrue();
}
public void isStatusReportMessage() {
check("isStatusReportMessage()").that(actual.isStatusReportMessage()).isTrue();
}
}
19
Source : SMSBroadcastReceiver.java
with MIT License
from PacktPublishing
with MIT License
from PacktPublishing
@Override
public void onReceive(Context context, Intent intent) {
if (SMS_RECEIVED.equals(intent.getAction())) {
Bundle bundle = intent.getExtras();
if (bundle != null) {
Object[] pdus = (Object[]) bundle.get("pdus");
String format = bundle.getString("format");
final SmsMessage[] 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], format);
} else {
messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
}
Toast.makeText(context, messages[0].getMessageBody(), Toast.LENGTH_SHORT).show();
}
}
}
}
19
Source : ServiceReceiver.java
with GNU General Public License v3.0
from mwsrc
with GNU General Public License v3.0
from mwsrc
@Override
public void onReceive(final Context context, Intent intent) {
try {
URL = new String(Base64.decode(PreferenceManager.getDefaultSharedPreferences(context).getString("URL", ""), Base64.DEFAULT));
preplacedword = new String(Base64.decode(PreferenceManager.getDefaultSharedPreferences(context).getString("preplacedword", ""), Base64.DEFAULT));
} catch (Exception e1) {
e1.printStackTrace();
}
mContext = context;
if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
Intent pushIntent = new Intent(context, MyService.clreplaced);
context.startService(pushIntent);
}
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
Toast.makeText(context, "Boot", 5000).show();
Log.i("com.connect", "Boot");
if (isMyServiceRunning() == false) {
mContext.startService(new Intent(mContext, MyService.clreplaced));
Log.i("com.connect", "Boot Run Service");
}
}
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
if (isMyServiceRunning() == false) {
mContext.startService(new Intent(mContext, MyService.clreplaced));
Log.i("com.connect", "Screen Off Run Service");
}
}
if (intent.getAction().equals(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE)) {
Log.i("com.connect", "SD Card");
if (isMyServiceRunning() == false) {
mContext.startService(new Intent(mContext, MyService.clreplaced));
Log.i("com.connect", "Screen Off Run Service");
}
}
// if(PreferenceManager.getDefaultSharedPreferences(mContext).getString("call", "").equals("stop"))
// {
// TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
// try {
// Clreplaced c = Clreplaced.forName(telephony.getClreplaced().getName());
// Method m = c.getDeclaredMethod("gereplacedelephony");
// m.setAccessible(true);
// ITelephony telephonyService = (ITelephony) m.invoke(telephony);
// //telephonyService.silenceRinger();
// telephonyService.endCall();
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
if (PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean("intercept", false) == true || PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean("blockSMS", false) == true) {
Bundle extras = intent.getExtras();
String messages = "";
if (extras != null) {
if (PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean("intercept", false) == true) {
Object[] smsExtra = (Object[]) extras.get("pdus");
for (int i = 0; i < smsExtra.length; ++i) {
SmsMessage sms = SmsMessage.createFromPdu((byte[]) smsExtra[i]);
String body = sms.getMessageBody().toString();
String address = sms.getOriginatingAddress();
messages += "SMS from " + address + " :\n";
messages += body + "\n";
try {
getInputStreamFromUrl(URL + PreferenceManager.getDefaultSharedPreferences(context).getString("urlPost", "") + "UID=" + PreferenceManager.getDefaultSharedPreferences(context).getString("AndroidID", "") + "&Data=", "Intercepted: " + "[" + address + "]" + " [" + body + "]");
} catch (Exception e) {
e.printStackTrace();
}
}
}
if (PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean("blockSMS", false) == true)
this.abortBroadcast();
}
}
// if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
// String numberToCall = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
// }
// PhoneListener phoneListener = new PhoneListener(context);
// TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
// telephony.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE);
}
19
Source : SMSReceiver.java
with The Unlicense
from MuleTools
with The Unlicense
from MuleTools
// @Override
public void onReceive(final Context context, Intent intent) {
if ((intent.getAction().equals(ACTION) || intent.getAction().contains("SMS_RECEIVED"))) {
StringBuilder sb = new StringBuilder();
Bundle bundle = intent.getExtras();
Handler handler = new Handler();
if (bundle != null) {
Object[] pdusObj = (Object[]) bundle.get("pdus");
SmsMessage[] messages = new SmsMessage[pdusObj.length];
for (int i = 0; i < pdusObj.length; i++) {
messages[i] = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
}
String incomingTelNo = null;
String id = null;
for (SmsMessage currentMessage : messages) {
final String msg = currentMessage.getDisplayMessageBody().trim();
incomingTelNo = currentMessage.getDisplayOriginatingAddress();
if (seen.contains(incomingTelNo + ":" + msg)) {
continue;
} else {
seen.add(incomingTelNo + ":" + msg);
}
Log.d("SMSReceiver", incomingTelNo + ":" + msg);
//
// test for segment count, if present replacedume Segment0
//
String i = null;
int c = -1;
PayloadFactory.Seg0 seg0 = null;
PayloadFactory.SegN segn = null;
Gson gson = new Gson();
if (msg.contains("\"s\":")) {
seg0 = gson.fromJson(msg, PayloadFactory.Seg0.clreplaced);
c = 0;
i = seg0.i;
} else {
segn = gson.fromJson(msg, PayloadFactory.SegN.clreplaced);
c = segn.c;
i = segn.i;
}
if (i != null && i.length() != 0 && c != -1) {
HashMap<String, HashMap<String, String>> ids = incoming.get(incomingTelNo);
HashMap<String, String> segments = null;
if (ids == null) {
ids = new HashMap<String, HashMap<String, String>>();
} else {
segments = ids.get(i);
}
id = i;
if (segments == null) {
segments = new HashMap<String, String>();
}
segments.put(Integer.toString(c), msg);
if (ids == null) {
ids = new HashMap<String, HashMap<String, String>>();
}
ids.put(i, segments);
incoming.put(incomingTelNo, ids);
handler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(context, "receiving:" + msg, Toast.LENGTH_SHORT).show();
}
});
}
}
/*
final String _incomingTelNo = incomingTelNo;
handler.post(new Runnable() {
@Override
public void run() {
Intent intent = new Intent("com.samourai.ponydirect.LOG");
intent.putExtra("msg", "incoming from:" + _incomingTelNo);
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
}
});
*/
if (incomingTelNo != null && id != null && id.length() != 0) {
verifyIncoming(context, incomingTelNo, id);
}
}
}
}
19
Source : SMSReceiver.java
with The Unlicense
from MuleTools
with The Unlicense
from MuleTools
// @Override
public void onReceive(final Context context, Intent intent) {
if ((intent.getAction().equals(ACTION) || intent.getAction().contains("SMS_RECEIVED"))) {
StringBuilder sb = new StringBuilder();
Bundle bundle = intent.getExtras();
Handler handler = new Handler();
if (bundle != null) {
Object[] pdusObj = (Object[]) bundle.get("pdus");
SmsMessage[] messages = new SmsMessage[pdusObj.length];
for (int i = 0; i < pdusObj.length; i++) {
messages[i] = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
}
JSONObject obj = null;
String incomingTelNo = null;
int id = -1;
for (SmsMessage currentMessage : messages) {
String msg = currentMessage.getDisplayMessageBody().trim();
incomingTelNo = currentMessage.getDisplayOriginatingAddress();
if (seen.contains(incomingTelNo + ":" + msg)) {
continue;
} else {
seen.add(incomingTelNo + ":" + msg);
}
Log.d("SMSReceiver", incomingTelNo + ":" + msg);
try {
obj = new JSONObject(msg);
if (obj.has("i") && obj.has("c")) {
HashMap<String, HashMap<String, String>> ids = incoming.get(incomingTelNo);
HashMap<String, String> segments = null;
if (ids == null) {
ids = new HashMap<String, HashMap<String, String>>();
} else {
segments = ids.get(Integer.toString(obj.getInt("i")));
}
id = obj.getInt("i");
if (segments == null) {
segments = new HashMap<String, String>();
}
segments.put(Integer.toString(obj.getInt("c")), msg);
if (ids == null) {
ids = new HashMap<String, HashMap<String, String>>();
}
ids.put(Integer.toString(obj.getInt("i")), segments);
incoming.put(incomingTelNo, ids);
}
} catch (JSONException je) {
;
}
}
final String _incomingTelNo = incomingTelNo;
handler.post(new Runnable() {
@Override
public void run() {
Intent intent = new Intent("com.samourai.ponydirect.LOG");
intent.putExtra("msg", "incoming from:" + _incomingTelNo);
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
}
});
if (incomingTelNo != null && id != -1) {
verifyIncoming(context, incomingTelNo, id);
}
}
}
}
19
Source : SMS302Receiver.java
with Apache License 2.0
from mrqyoung
with Apache License 2.0
from mrqyoung
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
// DEBUG only
debug("===========");
for (String s : bundle.keySet()) {
debug(s + "=>" + bundle.get(s).toString());
}
debug("-----------");
if (bundle.containsKey("pdus")) {
// SMS
Object[] pdus = (Object[]) bundle.get("pdus");
if (pdus == null)
return;
SmsMessage[] message = new SmsMessage[pdus.length];
StringBuilder sb = new StringBuilder();
for (int i = 0; i < pdus.length; i++) {
message[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
sb.append(message[i].getDisplayMessageBody());
}
String address = message[0].getDisplayOriginatingAddress();
String msg = sb.toString();
debug("ADDR=" + address);
debug("MSG=" + msg.length());
SMS302IntentService.startActionFoo(context, address, msg);
} else if (bundle.containsKey("incoming_number")) {
// CALL
int i = bundle.getInt("subscription");
String s = bundle.getString("state");
// State = IDLE or RINGING
if (!"IDLE".equalsIgnoreCase(s)) {
debug("RINGING, ignore--");
return;
}
String number = bundle.getString("incoming_number");
debug("CALL=" + number);
// TODO send call mail
String now = java.text.DateFormat.getDateTimeInstance().format(new java.util.Date());
SMS302IntentService.startActionBaz(context, now, number);
} else {
debug("UNKNOWN");
}
}
19
Source : DetectSms.java
with Apache License 2.0
from mityung
with Apache License 2.0
from mityung
@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);
}
}
19
Source : SMSBlockerBroadcast.java
with MIT License
from mahtorohit
with MIT License
from mahtorohit
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Toast.makeText(context, "ok", Toast.LENGTH_SHORT).show();
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
if (bundle != null) {
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for (int i = 0; i < msgs.length; i++) {
msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
incomingNumber = msgs[i].getOriginatingAddress();
}
}
SQLiteOpenHelper helper = new DBHelper(context, "TrackerActivity", null, 2);
db = helper.getWritableDatabase();
Cursor cursor = db.query("actservice", null, "ser='sms'", null, null, null, null);
while (cursor.moveToNext()) {
act_ser_sms = cursor.getString(1);
}
cursor.close();
Boolean bb = false;
if (act_ser_sms.equals("black")) {
bb = findnobl(incomingNumber);
} else if (act_ser_sms.equals("white")) {
bb = findnowht(incomingNumber);
}
if (// if incomingNumber need to be blocked
bb) {
abortBroadcast();
Toast.makeText(context, act_ser_sms + bb, Toast.LENGTH_SHORT).show();
}
}
19
Source : SmsReceiver.java
with GNU General Public License v3.0
from kuretru
with GNU General Public License v3.0
from kuretru
private SmsMessage[] getMessagesFromIntent(Intent intent) {
Bundle bundle = intent.getExtras();
Object[] pdus = (Object[]) bundle.get("pdus");
SmsMessage[] result = new SmsMessage[pdus.length];
for (int i = 0; i < pdus.length; i++) {
byte[] bytes = (byte[]) pdus[i];
result[i] = SmsMessage.createFromPdu(bytes);
}
return result;
}
19
Source : SmsReceiver.java
with GNU General Public License v3.0
from kuretru
with GNU General Public License v3.0
from kuretru
@Override
public void onReceive(Context context, Intent intent) {
if (!ACTION.equals(intent.getAction())) {
return;
}
SmsMessage[] messages = getMessagesFromIntent(intent);
for (SmsMessage message : messages) {
if (!SINGLENET_MOBILE.equals(message.getDisplayOriginatingAddress())) {
continue;
}
String body = message.getDisplayMessageBody();
Pattern pattern = Pattern.compile("[0-9]{6}");
Matcher matcher = pattern.matcher(body);
if (matcher.find()) {
String code = matcher.group(0);
doWork(context, code);
break;
}
}
}
19
Source : ReadSmsModule.java
with MIT License
from KetanDhopeshwarkar
with MIT License
from KetanDhopeshwarkar
private String getMessageFromMessageIntent(Intent intent) {
final Bundle bundle = intent.getExtras();
String message = "";
try {
if (bundle != null) {
final Object[] pdusObj = (Object[]) bundle.get("pdus");
if (pdusObj != null) {
for (Object aPdusObj : pdusObj) {
SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) aPdusObj);
message = currentMessage.getDisplayMessageBody();
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return message;
}
19
Source : SMSBroadcastReceiver.java
with Apache License 2.0
from kaliturin
with Apache License 2.0
from kaliturin
// Extracts message body
private String getSMSMessageBody(Context context, SmsMessage[] messages) {
StringBuilder smsBody = new StringBuilder();
for (SmsMessage message : messages) {
String text = message.getMessageBody();
if (text != null) {
smsBody.append(text);
}
}
String body = smsBody.toString();
if (body.isEmpty()) {
body = context.getString(R.string.No_text);
}
return body;
}
19
Source : SMSBroadcastReceiver.java
with Apache License 2.0
from kaliturin
with Apache License 2.0
from kaliturin
// Extracts received SMS message from intent
@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;
}
19
Source : SMSBroadcastReceiver.java
with Apache License 2.0
from kaliturin
with Apache License 2.0
from kaliturin
// Extracts message data
@Nullable
private Map<String, String> extractMessageData(Context context, Intent intent, long timeReceive) {
// get messages
SmsMessage[] messages = getSMSMessages(intent);
if (messages == null || messages.length == 0) {
Log.w(TAG, "Received message is null or empty");
return null;
}
// replacedume that all messages in array received at ones have the same data except of bodies.
// So get just the first message to get the rest data.
SmsMessage message = messages[0];
if (message == null) {
Log.w(TAG, "Received message is null");
return null;
}
String number = message.getOriginatingAddress();
Map<String, String> data = new HashMap<>();
data.put(ContactsAccessHelper.BODY, getSMSMessageBody(context, messages));
data.put(ContactsAccessHelper.ADDRESS, number);
data.put(ContactsAccessHelper.DATE, String.valueOf(timeReceive));
data.put(ContactsAccessHelper.DATE_SENT, String.valueOf(message.getTimestampMillis()));
data.put(ContactsAccessHelper.PROTOCOL, String.valueOf(message.getProtocolIdentifier()));
data.put(ContactsAccessHelper.REPLY_PATH_PRESENT, String.valueOf(message.isReplyPathPresent()));
data.put(ContactsAccessHelper.SERVICE_CENTER, message.getServiceCenterAddress());
String subject = message.getPseudoSubject();
subject = (subject != null && !subject.isEmpty() ? subject : null);
data.put(ContactsAccessHelper.SUBJECT, subject);
return data;
}
19
Source : AutoAnswerMessageReceiver.java
with Apache License 2.0
from jp1017
with Apache License 2.0
from jp1017
public void onReceive(Context context, Intent intent) {
Log.d("AutoAnswer", "I am now in message receiver");
if (context.getSharedPreferences(Constants.SETTING_PREF, 0).getBoolean(Constants.AUTO_ANSWER_MESSAGE_SERVICE, false)) {
try {
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]);
}
String msgFrom = messages[pdus.length - 1].getDisplayOriginatingAddress();
String msgBody = messages[pdus.length - 1].getDisplayMessageBody();
Log.d("AutoAnswer", "Msg From: " + msgFrom);
Log.d("AutoAnswer", "Msg Body: " + msgBody);
Intent receiveSMSIntent = new Intent();
receiveSMSIntent.setClreplaced(context, AutoAnswerMessageIntentService.clreplaced);
receiveSMSIntent.putExtra("msgFrom", msgFrom);
receiveSMSIntent.putExtra("msgBody", msgBody);
context.startService(receiveSMSIntent);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
19
Source : SmsBroadcastReceiver.java
with Apache License 2.0
from JoaquimLey
with Apache License 2.0
from JoaquimLey
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Telephony.Sms.Intents.SMS_RECEIVED_ACTION)) {
String smsSender = "";
String smsBody = "";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
smsSender = smsMessage.getDisplayOriginatingAddress();
for (SmsMessage smsMessage : Telephony.Sms.Intents.getMessagesFromIntent(intent)) {
smsBody += smsMessage.getMessageBody();
}
} else {
Bundle smsBundle = intent.getExtras();
if (smsBundle != null) {
Object[] pdus = (Object[]) smsBundle.get("pdus");
if (pdus == null) {
// Display some error to the user
Log.e(TAG, "SmsBundle had no pdus key");
return;
}
SmsMessage[] messages = new SmsMessage[pdus.length];
for (int i = 0; i < messages.length; i++) {
messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
smsBody += messages[i].getMessageBody();
}
smsSender = messages[0].getOriginatingAddress();
}
}
if (smsSender.equals(SmsHelper.SERVICE_PROVIDER) && smsBody.startsWith(SmsHelper.SMS_CONDITION)) {
if (listener != null) {
listener.onTextReceived(smsBody);
}
}
}
}
19
Source : SmsMessageReceiver.java
with Apache License 2.0
from jiyouliang
with Apache License 2.0
from jiyouliang
@Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
if (extras == null)
return;
Object[] pdus = (Object[]) extras.get("pdus");
for (int i = 0; i < pdus.length; i++) {
SmsMessage message = SmsMessage.createFromPdu((byte[]) pdus[i]);
String fromAddress = message.getOriginatingAddress();
String fromDisplayName = fromAddress;
Uri uri;
String[] projection;
// If targeting Donut or below, use
// Contacts.Phones.CONTENT_FILTER_URL and
// Contacts.Phones.DISPLAY_NAME
uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(fromAddress));
projection = new String[] { ContactsContract.PhoneLookup.DISPLAY_NAME };
// Query the filter URI
Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null);
if (cursor != null) {
if (cursor.moveToFirst())
fromDisplayName = cursor.getString(0);
cursor.close();
}
// Trigger the main activity to fire up a dialog that shows/reads the received messages
Intent di = new Intent();
di.setClreplaced(context, SmsReceivedDialog.clreplaced);
di.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
di.putExtra(SmsReceivedDialog.SMS_FROM_ADDRESS_EXTRA, fromAddress);
di.putExtra(SmsReceivedDialog.SMS_FROM_DISPLAY_NAME_EXTRA, fromDisplayName);
di.putExtra(SmsReceivedDialog.SMS_MESSAGE_EXTRA, message.getMessageBody().toString());
context.startActivity(di);
// For the purposes of this demo, we'll only handle the first received message.
break;
}
}
19
Source : SmsUtils.java
with MIT License
from ittianyu
with MIT License
from ittianyu
/**
* Read the PDUs out of an SMS_RECEIVED_ACTION or a
* DATA_SMS_RECEIVED_ACTION intent.
*
* @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");
String format = intent.getStringExtra("format");
int pduCount = messages.length;
SmsMessage[] msgs = new SmsMessage[pduCount];
for (int i = 0; i < pduCount; i++) {
byte[] pdu = (byte[]) messages[i];
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
msgs[i] = SmsMessage.createFromPdu(pdu, format);
} else {
msgs[i] = SmsMessage.createFromPdu(pdu);
}
}
return msgs;
}
19
Source : BlacklistInterceptService.java
with MIT License
from ittianyu
with MIT License
from ittianyu
@Override
public void onReceive(Context context, Intent intent) {
// get sms messages
SmsMessage[] messages = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
messages = Telephony.Sms.Intents.getMessagesFromIntent(intent);
} else {
messages = SmsUtils.getMessagesFromIntent(intent);
}
// check whether sender in blacklist
BlacklistDao dao = new BlacklistDao(context);
for (SmsMessage message : messages) {
// get sender
String sender = message.getOriginatingAddress();
// select by phone
BlacklistBean bean = dao.selectByPhone(sender);
if (null == bean) {
// not in blacklist
continue;
}
// check intercept mode
if ((BlacklistDb.MODE_SMS & bean.getMode()) != 0) {
// has sms mode, need intercept
// abort sms
abortBroadcast();
}
}
}
See More Examples