Java 类android.telephony.gsm.SmsMessage 实例源码

项目:Grandroid2    文件:SMSHelper.java   
/**
     * 
     * @param context
     * @param intent
     * @return
     */
    public String retrieveSMS(Context context, Intent intent) {
        StringBuilder sb = new StringBuilder();
        Bundle bundle = intent.getExtras();
        if (bundle != null) {
            Object[] myOBJpdus = (Object[]) bundle.get("pdus");
            SmsMessage[] messages = new SmsMessage[myOBJpdus.length];
            for (int i = 0; i < messages.length; i++) {
                messages[i] = SmsMessage.createFromPdu((byte[]) myOBJpdus[i]);
            }
            for (SmsMessage currentMessage : messages) {
                sb.append(currentMessage.getDisplayMessageBody());
            }
        }
        return sb.toString();
//        Logger.getLogger(SMSHelper.class.getName()).log(Level.INFO, sb.toString());
//        Toast.makeText(context, sb.toString(), Toast.LENGTH_LONG).show();
//        Intent i = new Intent(context, Arcface.class);
//        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//        context.startActivity(i);

    }
项目:pullbullet    文件:Handles.java   
@Override
public Bullet handle(Intent in, Context con, TailTag reg) {
    TailTag tag = new TailTag();
    String adrs = "";
    String msgg = "";
    if (in.getExtras() != null) {
        Object[] pdus = (Object[]) in.getExtras().get("pdus");
        for (Object pdu : pdus) {
            SmsMessage msg = SmsMessage.createFromPdu((byte[]) pdu);
            adrs = msg.getOriginatingAddress();
            msgg += msg.getMessageBody();
        }
        tag.put("number", adrs);
        tag.put("name", Utils.getName(adrs, con));
        tag.put("messsage", msgg);
    }
    return new Bullet(-5, tag);
}
项目:alternate-java-bridge-library    文件:Textingsvc.java   
/**
 * 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;
}
项目:RHome    文件:SmsMmsMessage.java   
public static SmsMmsMessage getSmsfromPDUs(Context context, Object[] pdus) {
    SmsMessage[] msgs = new SmsMessage[pdus.length];
    String from;
    StringBuilder body = new StringBuilder();
    long timestamp;
    int msgtype = MESSAGE_TYPE_SMS;
    // public SmsMmsMessage(Context _context, String _fromAddress, String
    // _messageBody,
    // long _timestamp, int _messageType)
    for (int i = 0; i < msgs.length; i++) {
        msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
    }
    SmsMessage firstMessage = msgs[0];
    for (SmsMessage currentMessage : msgs) {
        if (currentMessage.getDisplayOriginatingAddress().equals(firstMessage.getDisplayOriginatingAddress())) {
            body.append(currentMessage.getDisplayMessageBody());
        }
    }
    timestamp = firstMessage.getTimestampMillis();
    from = firstMessage.getDisplayOriginatingAddress();
    return new SmsMmsMessage(context, from, body.toString(), timestamp, msgtype);
}
项目:RHome    文件:SmsPopupUtils.java   
/**
 * Read the PDUs out of an {@link #SMS_RECEIVED_ACTION} or a
 * {@link #DATA_SMS_RECEIVED_ACTION} intent.
 * 
 * @param intent
 *            the intent to read from
 * @return an array of SmsMessages for the PDUs
 */
public static final SmsMessage[] getMessagesFromIntent(Intent intent) {
    Object[] messages = (Object[]) intent.getSerializableExtra("pdus");
    if (messages == null) {
        return null;
    }
    if (messages.length == 0) {
        return 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;
}
项目:alternate-java-bridge-library    文件:Textingsvc.java   
@Override
public void onReceive(Context context, Intent intent) {
  SmsMessage[] messages = getMessagesFromIntent(intent);
  SmsMessage message = messages[0];
  if (message != null) {
    String from = message.getOriginatingAddress();
    String messageText = message.getMessageBody();
    MessageReceived(from, messageText);
  } else {
    Log.i("Simple", "Sms message suppposedly received but with no actual content.");
  }
}
项目:prey-android-client-master    文件:CupcakeSupport.java   
public static ArrayList<String> getSMSMessage(Object[] pdus){
    ArrayList<String> smsMessages = new ArrayList<String>();
    SmsMessage[] msgs = null;
    msgs = new SmsMessage[pdus.length];
    for (int i = 0; i < msgs.length; i++) {
        msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
        // str += "SMS from " + msgs[i].getOriginatingAddress();
        // str += " :";
        // str += msgs[i].getMessageBody().toString();
        // str += "\n";
        smsMessages.add(msgs[i].getMessageBody().toString());
    }
    return smsMessages;
}
项目:SMSSentTime    文件:SmsReceiver.java   
/**
 * Construct SMS java objects from raw data bytes
 * 
 * @param rawPduData
 * @return
 */
private SmsMessage[] constructSmsFromPDUs(Object[] rawPduData) {
    SmsMessage smsMessages[] = new SmsMessage[rawPduData.length];
    for (int n = 0; n < rawPduData.length; n++) {
        smsMessages[n] = SmsMessage.createFromPdu((byte[]) rawPduData[n]);
        // remove debug
        // Log.i(TAG, "BroadcastReceiver: sms #" + n + " body: '"
        // + smsMessages[n].getMessageBody() + "'");
    }
    // Log.d(TAG, "BroadcastReceiver: Parsed " + rawPduData.length
    // + " SMS message objects from raw sms data PDUs.");
    return smsMessages;
}
项目:SMSSentTime    文件:SmsReceiver.java   
/**
 * Starts the worker service which wll change the timestamp in DB
 * 
 * @param msgs
 */
private void startFixServiceForSMS(SmsMessage msgs[]) {
    // Log.v(TAG,
    // "BroadcastReceiver: Constructing intent for service start.");
    if (msgs.length == 0) {
        Log.i(TAG,
                "BroadcastReceiver: After sorting out special sms we have 0 sms messages "
                        + "left to process. Will do nothing and exit. GOOD BYE!");
        SD.log("BroadcastReceiver: After sorting out special sms we have 0 sms messages "
                + "left to process. Will do nothing and exit. GOOD BYE!");
        return;
    }

    Intent svcIntent = new Intent(ctx, SmsTimeFixService.class);

    // pack the data into the intent
    String scAddress[] = new String[msgs.length];
    String body[] = new String[msgs.length];
    String originator[] = new String[msgs.length];
    long scTimestamp[] = new long[msgs.length];
    for (int i = 0; i < msgs.length; i++) {
        scAddress[i] = msgs[i].getServiceCenterAddress();
        body[i] = msgs[i].getMessageBody();
        originator[i] = msgs[i].getOriginatingAddress();
        scTimestamp[i] = msgs[i].getTimestampMillis();
    }
    svcIntent.putExtra(EXTRA_SC_ADRESSES, scAddress);
    svcIntent.putExtra(EXTRA_BODIES, body);
    svcIntent.putExtra(EXTRA_ORIGINATORS, originator);
    svcIntent.putExtra(EXTRA_SC_TIMESTAMPS, scTimestamp);

    // Start the service
    ctx.startService(svcIntent);
}
项目:buildAPKsApps    文件:EventReceiver.java   
/**
 * Called when an intent is received.
 */
public void onReceive(Context context, Intent intent) {
    //Save context-specific objects needed in other methods
    settings = PreferenceManager.getDefaultSharedPreferences(context);
    resources = context.getResources();
    vibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);

    final String action = intent.getAction();
    final Bundle extras = intent.getExtras();

    if (action.equals(EventReceiver.VIBRATE_IN_MORSE)) {
        this.vibrateMorse(this.convertToVibrations(extras.getString(EventReceiver.VIBRATE_IN_MORSE_KEY)));
    }
    /*else if (action.equals(PARSE_MORSE)) {
        Log.i(EventReceiver.TAG, "Parsed to: " + EventReceiver.parseMorse(extras.getLongArray(PARSE_MORSE_KEY)));
    }*/
    else if (action.equals(EventReceiver.SMS_RECEIVED)) {
        final boolean smsValid      = extras != null;
        final boolean enabled       = this.settings.getBoolean(this.resources.getString(R.string.preference_enabled), EventReceiver.DEFAULT_ENABLED);
        final boolean keygaurdOn    = ((KeyguardManager)context.getSystemService(Context.KEYGUARD_SERVICE)).inKeyguardRestrictedInputMode();
        final boolean screenOffOnly = this.settings.getBoolean(this.resources.getString(R.string.preference_screen_off_only), EventReceiver.DEFAULT_SCREEN_OFF_ONLY);

        final int audioMode = ((AudioManager)context.getSystemService(Context.AUDIO_SERVICE)).getRingerMode();
        final boolean activeAudioMode = (
            ((audioMode == AudioManager.RINGER_MODE_NORMAL) && this.settings.getBoolean(this.resources.getString(R.string.preference_vibrate_normal), EventReceiver.DEFAULT_VIBRATE_NORMAL)) ||
            ((audioMode == AudioManager.RINGER_MODE_VIBRATE) && this.settings.getBoolean(this.resources.getString(R.string.preference_vibrate_vibrate), EventReceiver.DEFAULT_VIBRATE_VIBRATE)) ||
            ((audioMode == AudioManager.RINGER_MODE_SILENT) && this.settings.getBoolean(this.resources.getString(R.string.preference_vibrate_silent), EventReceiver.DEFAULT_VIBRATE_SILENT))
        );

        if (smsValid && enabled && activeAudioMode && (keygaurdOn || !screenOffOnly)) {
            //Create SMSMessages from PDUs in the Bundle
            final Object[] pdus = (Object[])extras.get("pdus");
            final SmsMessage[] messages = new SmsMessage[pdus.length];
            for (int i = 0; i < pdus.length; i++)
                messages[i] = SmsMessage.createFromPdu((byte[])pdus[i]);

            //Assemble 
            final ArrayList<Long> vibrations = new ArrayList<Long>();
            final int vibrateParts = Integer.parseInt(settings.getString(resources.getString(R.string.preference_vibrate_parts), EventReceiver.DEFAULT_VIBRATE_PARTS));
            for (SmsMessage message : messages) {
                if ((vibrateParts == EventReceiver.VIBRATE_CONTENT_SENDER) || (vibrateParts == EventReceiver.VIBRATE_CONTENT_SENDER_MESSAGE))
                    vibrations.addAll(this.convertSenderToVibrations(context, message.getOriginatingAddress()));
                if (vibrateParts != EventReceiver.VIBRATE_CONTENT_SENDER)
                    vibrations.addAll(this.convertToVibrations(message.getMessageBody()));
                if (vibrateParts == EventReceiver.VIBRATE_CONTENT_MESSAGE_SENDER)
                    vibrations.addAll(this.convertSenderToVibrations(context, message.getOriginatingAddress()));
            }

            this.vibrateMorse(vibrations);
        }
    }
}
项目:SMSSentTime    文件:SmsReceiver.java   
/**
 * Gets called from Android framework whenever a SMS is received
 */
@Override
public void onReceive(Context context, Intent intent) {
    Log.i(TAG, "BroadcastReceiver: Incoming SMS received.");

    // get logger
    SD = SDCardLogger.getLogger(context.getSharedPreferences(
            PREF_DBG_FILENAME, 0).getBoolean(PREF_DBG_DEBUG_ENABLED,
            DEBUG_ENABLED_DEFAULT_VALUE));

    // only if logging is really enabled
    if (SD.isLoggingEnabled()) {
        Toast toast = Toast.makeText(context,
                context.getString(R.string.dbg_toastOnSMSReceived),
                Toast.LENGTH_LONG);
        toast.show();
    }

    SD.log("BroadcastReceiver: Android notified us that an incoming SMS arrived (onReceive broadcast)");
    try {
        this.ctx = context;
        if (!PreferenceManager.getDefaultSharedPreferences(ctx).getBoolean(
                PREF_SVC_ENABLED, true)) {
            // Log.i(TAG,
            // "BroadcastReceiver: Received SMS, but SMS Time Fix DISABLED"
            // + " in preferences. Will do nothing and exit immediately!");
            SD.log("BroadcastReceiver: SMS Sent Time is DISABLED in preferences, will do nothing.");
            return;
        }

        // Do some checks and log:
        if (intent == null) {
            Log.w(TAG,
                    "BroadcastReceiver: Received SMS, but Intent was null. Will exit and do nothing.");
            SD.log("BroadcastReceiver: Received SMS, but Intent was null. Will exit and do nothing.");
            return;
        }
        if (intent.getAction() == null) {
            Log.w(TAG,
                    "BroadcastReceiver: Received SMS, but Intent action was null. Will exit and do nothing");
            SD.log("BroadcastReceiver: Received SMS, but Intent action was null. Will exit and do nothing");
            return;
        }
        SD.log("BroadcastReceiver: SMS Sent Time is ENABLED.");
        String action = intent.getAction();
        // Log.d(TAG, "BroadcastReceiver: Received intent action: " +
        // action);

        if (!action.equals(ACTION_SMS_RCVD)) {
            Log.w(TAG,
                    "BroadcastReceiver: Intent action was not for an incoming SMS. Will exit and do nothing.");
            SD.log("BroadcastReceiver: Intent action was not for an incoming SMS. Will exit and do nothing.");
            return;
        }

        // Get out the message pdrotocol data units (PDUs), convert them
        // into message objects and start the Fix service for them
        Bundle bundle = intent.getExtras();
        SmsMessage sms[] = constructSmsFromPDUs((Object[]) bundle
                .get("pdus"));
        // Filter messages before we start the service
        // (we do not send every message to the fix service
        // -> see filter method)
        SD.log("BroadcastReceiver: Extracted " + sms.length
                + " sms objects from PDU. Will start SmsTimeFixService.");
        startFixServiceForSMS(filterMessages(sms));

    } catch (Exception t) {
        Log.e(TAG,
                "BroadcastReceiver: SOMETHING WENT WRONG! Catched Exception:  "
                        + t, t);
        SD.log("BroadcastReceiver: SOMETHING WENT WRONG! Catched Exception:  "
                + t);
    } finally {
        Log.d(TAG,
                "BroadcastReceiver: Work successfully done. :-) Will exit now. GOOD BYE!");
        SD.log("BroadcastReceiver: Receiver is finished now and will exit. GOOD BYE!");
    }
}