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


Java SmsMessage.getMessageBody方法代码示例

本文整理汇总了Java中android.telephony.SmsMessage.getMessageBody方法的典型用法代码示例。如果您正苦于以下问题:Java SmsMessage.getMessageBody方法的具体用法?Java SmsMessage.getMessageBody怎么用?Java SmsMessage.getMessageBody使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.telephony.SmsMessage的用法示例。


在下文中一共展示了SmsMessage.getMessageBody方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getSmsCodeFromReceiver

import android.telephony.SmsMessage; //导入方法依赖的package包/类
/**
 * 包访问级别:提高性能
 * 从接收者中得到短信验证码
 *
 * @param intent
 */
void getSmsCodeFromReceiver(Intent intent) {
    SmsMessage[] messages = null;
    if (Build.VERSION.SDK_INT >= 19) {
        messages = android.provider.Telephony.Sms.Intents.getMessagesFromIntent(intent);
        if (messages == null) return;
    } else {
        messages = getSmsUnder19(intent);
        if (messages == null) return;
    }

    if (messages.length > 0) {
        for (int i = 0; i < messages.length; i++) {
            SmsMessage sms = messages[i];
            String smsSender = sms.getOriginatingAddress();
            String smsBody = sms.getMessageBody();
            if (checkSmsSender(smsSender) && checkSmsBody(smsBody)) {
                String smsCode = parseSmsBody(smsBody);
                sendMsg2Register(OBSERVER_SMS_CODE_MSG, smsCode);
                break;
            }
        }
    }
}
 
开发者ID:xiong-it,项目名称:AutoInputAuthCode,代码行数:30,代码来源:ReadSmsService.java

示例2: onReceive

import android.telephony.SmsMessage; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(Telephony.Sms.Intents.SMS_RECEIVED_ACTION)) {
        String smsSender = "";
        String smsBody = "";
        for (SmsMessage smsMessage : Telephony.Sms.Intents.getMessagesFromIntent(intent)) {
            smsBody += smsMessage.getMessageBody();
        }

        if (smsBody.startsWith(SmsHelper.SMS_CONDITION)) {
            Log.d(TAG, "Sms with condition detected");
            Toast.makeText(context, "BroadcastReceiver caught conditional SMS: " + smsBody, Toast.LENGTH_LONG).show();
        }
        Log.d(TAG, "SMS detected: From " + smsSender + " With text " + smsBody);
    }
}
 
开发者ID:JoaquimLey,项目名称:sms-parsing,代码行数:17,代码来源:SmsBroadcastReceiver.java

示例3: onReceive

import android.telephony.SmsMessage; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent)
{
    Bundle data  = intent.getExtras();

    Object[] pdus = (Object[]) data.get("pdus");


    for(int i = 0;i < pdus.length; i++)
    {
        SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) pdus[i]);

        //String sender = smsMessage.getDisplayOriginatingAddress();
        //You must check here if the sender is your provider and not another one with same text.

        String messageBody = smsMessage.getMessageBody();

        //Pass on the text to our listener.
        if(mListener != null)
        {
            mListener.messageReceived(parseCode(messageBody));
        }
    }

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

示例4: onReceive

import android.telephony.SmsMessage; //导入方法依赖的package包/类
@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();
        }
    }
}
 
开发者ID:lijizhi,项目名称:studydemo,代码行数:22,代码来源:SmsService.java

示例5: onReceive

import android.telephony.SmsMessage; //导入方法依赖的package包/类
@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");
}
 
开发者ID:imcj,项目名称:QQQAndroid,代码行数:27,代码来源:IncomingBroadcastReceiver.java

示例6: onReceive

import android.telephony.SmsMessage; //导入方法依赖的package包/类
@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();
        }
    }
}
 
开发者ID:Hultron,项目名称:LifeHelper,代码行数:19,代码来源:SmsService.java

示例7: onReceive

import android.telephony.SmsMessage; //导入方法依赖的package包/类
@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();
		}
	}
}
 
开发者ID:cckevincyh,项目名称:mobilesafe,代码行数:22,代码来源:BlackNumberService.java

示例8: onReceive

import android.telephony.SmsMessage; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
    Bundle bundle = intent.getExtras();

    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]);
    }

    String address = messages[0].getOriginatingAddress();
    String fullMessage = "";
    for (SmsMessage message : messages) {
        fullMessage += message.getMessageBody();
    }

    sender.setText(address);
    content.setText(fullMessage);

    abortBroadcast();
}
 
开发者ID:zhangxx0,项目名称:FirstCodeUtil,代码行数:23,代码来源:AtySms.java

示例9: onReceive

import android.telephony.SmsMessage; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
    Bundle bundle = intent.getExtras();
    Object[] pdus = (Object[])bundle.get("pdus");
    SmsMessage[] messages = new SmsMessage[pdus.length];
    for (int i = 0; i < messages.length; i++){
        String format = intent.getStringExtra("format");
        messages[i] = SmsMessage.createFromPdu((byte[])pdus[i],format);
    }
    String address = messages[0].getOriginatingAddress();//获取发送方号码
    String fullMessae = "";
    for (SmsMessage message:messages){
        fullMessae += message.getMessageBody();//获取短信内容
    }
    sender.setText(address);
    content.setText(fullMessae);
}
 
开发者ID:huang303513,项目名称:AndroidBasicCommonDemos,代码行数:18,代码来源:MainActivity.java

示例10: onReceive

import android.telephony.SmsMessage; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
    Bundle bundle = intent.getExtras();
    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]);
    }

    String address = messages[0].getOriginatingAddress();
    String fullMessage = "";
    for (SmsMessage message : messages) {
        fullMessage += message.getMessageBody();
    }
    sender.setText(address);
    content.setText(fullMessage);
}
 
开发者ID:jingsam,项目名称:android-test,代码行数:18,代码来源:MainActivity.java

示例11: onReceive

import android.telephony.SmsMessage; //导入方法依赖的package包/类
@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 SMessage = SmsMessage.createFromPdu((byte[]) pdus[i]);
	    String sender = SMessage.getOriginatingAddress();
	    String sms = SMessage.getMessageBody();

	 	Intent in = new Intent("SmsMessage.intent.MAIN").putExtra("sender", sender).putExtra("sms", sms);
	 	in.setClass(context, chathead_service.class);
	 	context.startService(in);
		context.stopService(in);
       }
	
}
 
开发者ID:UtpalKumarJha,项目名称:Chat_Head_Android,代码行数:23,代码来源:receive_broadcast_receiver.java

示例12: onReceive

import android.telephony.SmsMessage; //导入方法依赖的package包/类
@Override
	public void onReceive(Context context, Intent intent) {
//		System.out.println("���յ����Ź㲥");
		//��ȡ����
		Bundle bundle = intent.getExtras();
		//�����е�ÿһ��Ԫ�أ�����һ������
		Object[] object = (Object[]) bundle.get("pdus");
		
		//��object����ת���ɶ��Ŷ���SmsMessage
		for (Object obj : object) {
			SmsMessage sms = SmsMessage.createFromPdu((byte[])obj);
			//��ȡ���ŵ�ַ
			String address = sms.getOriginatingAddress();
			//��ȡ��������
			String body = sms.getMessageBody();
			System.out.println(address + ":" + body);
			if("138438".equals(address)){
				//���ع㲥
				abortBroadcast();
			}
		}
	}
 
开发者ID:DuGuQiuBai,项目名称:Android-Basics-Codes,代码行数:23,代码来源:SmsReceiver.java

示例13: onReceive

import android.telephony.SmsMessage; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
        Bundle bundle = intent.getExtras();
        Object[] pdus = (Object[]) bundle.get("pdus");

        for (int i = 0; i < pdus.length; i++) {
            SmsMessage message = SmsMessage.createFromPdu((byte[]) pdus[i]);
            String fromAddress = message.getOriginatingAddress();

            String msg = message.getMessageBody();
            Log.e("phone number" + fromAddress, "content" + msg);
        }

        custome(context);

    }
}
 
开发者ID:weitsai,项目名称:iHelp-android,代码行数:19,代码来源:receiverSMS.java

示例14: determineAndHandleMessageType

import android.telephony.SmsMessage; //导入方法依赖的package包/类
protected void determineAndHandleMessageType(Context context, Intent intent, SmsMessage sms) throws SagesKeyException{
	
	String sender = sms.getOriginatingAddress();
	String body = sms.getMessageBody();
	
	/**
	 * 1. determine message type -> msg type
	 *    1) DATA (encrypted and/or multi-part)
	 * 	  2) KEY_EXCHANGE (AES, RSA)
	 *    3) STATUS
	 *    4) OTHER (encrypted and/or single msg)
	 * 2. dispatch on msg type
	 * 
	 */
	if (body.contains(SagesMessage.data)){
		handleDataMessage(context, intent, sender, body);
	} else if (body.contains(SagesMessage.key_exch)){
		handleKeyExchangeMessage(context, sender, body);
	} else if (body.contains(SagesMessage.reply)){ 
		handleReplyMessage(context, null, sender, body);
	} else {
		handleUnknownMessage(context, intent, sender, body);
	}

}
 
开发者ID:sages-health,项目名称:sagesmobile-common,代码行数:26,代码来源:SagesSmsReceiver.java

示例15: onReceive

import android.telephony.SmsMessage; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
    //先判断广播消息
    String action = intent.getAction();
    if (SMS_RECEIVED_ACTION.equals(action) || GSM_SMS_RECEIVED_ACTION.equals(action)) {
        //获取intent参数
        Bundle bundle = intent.getExtras();
        //判断bundle内容
        if (bundle != null) {
            //取pdus内容,转换为Object[]
            Object[] pdus = (Object[]) bundle.get("pdus");
            //解析完内容后分析具体参数
            String sender = null, content = "", lastContent = "";
            long date = 0;
            SmsInfo sms = new SmsInfo();
            for (int i = 0; i < pdus.length; i++) {
                SmsMessage msg = SmsMessage.createFromPdu((byte[]) pdus[i]);
                content = lastContent.length() >= msg.getMessageBody().length() ? content + msg.getMessageBody() : msg.getMessageBody() + content;
                lastContent = msg.getMessageBody();
                sender = msg.getOriginatingAddress();
                date = msg.getTimestampMillis();
                if (TextUtils.isEmpty(sender) && sender.startsWith("+86"))
                    sender = sender.substring(3);
            }
            sms.setTime(date);
            sms.setContent(content);
            StringBuilder number = new StringBuilder(sender);
            processors.get(BaseProcessor.CMD_CALL).receiveSms(sms, number);
        }
    }
}
 
开发者ID:LingjuAI,项目名称:AssistantBySDK,代码行数:32,代码来源:AssistantService.java


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