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


Java SmsMessage.getOriginatingAddress方法代码示例

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


在下文中一共展示了SmsMessage.getOriginatingAddress方法的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包/类
@TargetApi(Build.VERSION_CODES.KITKAT)
@Override
public void onReceive(Context receivedContext, Intent intent) {
    if (Intents.SMS_RECEIVED_ACTION.equals(intent.getAction())) {
        SnippetEvent event = new SnippetEvent(mCallbackId, SMS_RECEIVED_EVENT_NAME);
        Bundle extras = intent.getExtras();
        if (extras != null) {
            SmsMessage[] msgs = Intents.getMessagesFromIntent(intent);
            StringBuilder smsMsg = new StringBuilder();

            SmsMessage sms = msgs[0];
            String sender = sms.getOriginatingAddress();
            event.getData().putString("OriginatingAddress", sender);

            for (SmsMessage msg : msgs) {
                smsMsg.append(msg.getMessageBody());
            }
            event.getData().putString("MessageBody", smsMsg.toString());
            mEventCache.postEvent(event);
            mContext.unregisterReceiver(this);
        }
    }
}
 
开发者ID:google,项目名称:mobly-bundled-snippets,代码行数:24,代码来源:SmsSnippet.java

示例3: onReceive

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

    Bundle extras = intent.getExtras();
    if (extras == null)
        return;

    // To display mContext Toast whenever there is an SMS.
    // Toast.makeText(mainScriptContext,"Recieved",Toast.LENGTH_LONG).show();

    Object[] pdus = (Object[]) extras.get("pdus");
    for (int i = 0; i < pdus.length; i++) {
        SmsMessage SMessage = SmsMessage.createFromPdu((byte[]) pdus[i]);
        String sender = SMessage.getOriginatingAddress();
        String body = SMessage.getMessageBody().toString();

        // A custom Intent that will used as another Broadcast
        Intent in = new Intent("SmsMessage.intent.MAIN").putExtra("get_msg", sender + ":" + body);

        // You can place your check conditions here(on the SMS or the
        // sender)
        // and then send another broadcast
        context.sendBroadcast(in);

        // This is used to abort the broadcast and can be used to silently
        // process incoming message and prevent it from further being
        // broadcasted. Avoid this, as this is not the way to program an
        // app.
        // this.abortBroadcast();
    }
}
 
开发者ID:victordiaz,项目名称:phonk,代码行数:32,代码来源:SmsReceiver.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) {
	LogUtil.d(TAG, "�ڲ��㲥�����ߣ���������");
	//�����ŷ������Ƿ��������ϵ�ˣ�ģʽ�Ƿ�Ϊ�������ػ���ȫ������
	Object[] objs = (Object[]) intent.getExtras().get("pdus");
	
	for (Object obj : objs) {
		SmsMessage message = SmsMessage.createFromPdu((byte[])obj);
		//��ȡ�����˺���
		String sender = message.getOriginatingAddress();
		String mode = dao.findMode(sender);
		if ("2".equals(mode) || "3".equals(mode)) {
			abortBroadcast();
		}
	}
}
 
开发者ID:yoxin,项目名称:safety,代码行数:17,代码来源:CallSmsSafeService.java

示例9: 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

示例10: 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

示例11: 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 smsSender = SmsMessage.createFromPdu((byte[])pdus[0]);
    String sender = smsSender.getOriginatingAddress();
    Message textMessage = new Message(sender, managerType);
    Log.d("Sender", sender); //debug

    if(tmFilter.isBlackListed(textMessage))
    {
        AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        int prevAudioState = audioManager.getRingerMode();

        audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);

        new Timer().schedule(new MyTimerTask(audioManager, prevAudioState), 5000);
    }
}
 
开发者ID:ezargarpur,项目名称:AnnoyMeNot,代码行数:21,代码来源:Text_Manager.java

示例12: onReceive

import android.telephony.SmsMessage; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
	Object[] objs = (Object[]) intent.getExtras().get("pdus");
	for (Object obj : objs) {
		SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) obj);
		String sender = smsMessage.getOriginatingAddress();
		if (sender.length() == 14) {
			sender = sender.substring(3);
		}
		// 检查sender是否在黑名单列表里面 检查拦截模式. 短信拦截 全部拦截
		int mode = mBlacklistDao.findMode(sender);
		Logger.i(TAG, "收到短信 mode:" + mode);
		if (1 == mode || mode == 3) {
			Logger.i(TAG, "拦截黑名单短信\n发送者:" + sender + "\n短信内容" + smsMessage.getMessageBody());
			abortBroadcast();
			// TODO:把短信的内容 和 电话号码 时间 存起来.
		}
	}

}
 
开发者ID:bingoogolapple,项目名称:Graduation-Design,代码行数:21,代码来源:BlacklistInterceptService.java

示例13: onReceive

import android.telephony.SmsMessage; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
	Log.i(TAG, "内部广播接收者,短信到来了");
	// 检查发件人是否是黑名单号码,且设置了短信拦截或全部拦截
	Object[] objs = (Object[]) intent.getExtras().get("pdus");
	for (Object obj : objs) {
		SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) obj);
		String sender = smsMessage.getOriginatingAddress();
		String resultString = dao.findMode(sender);
		if ("2".equals(resultString) || "3".equals(resultString)) {
			Log.i(TAG, "拦截短信:" + sender + " 说:" + smsMessage.getMessageBody());
			abortBroadcast();
		}
	}

}
 
开发者ID:qq644531343,项目名称:MobileSafe,代码行数:17,代码来源:CallSMSSafeService.java

示例14: handleSMS

import android.telephony.SmsMessage; //导入方法依赖的package包/类
private void handleSMS(Context context, Bundle data) {
	Log.d("Event: ", "handle sms");
  	Object[] pdus = (Object[]) data.get("pdus");
    SmsMessage sms = SmsMessage.createFromPdu((byte[]) pdus[0]);	    	    
    String number = sms.getOriginatingAddress();
    String contactname = "";
    JSONObject jobject = new JSONObject();
    
    // get Contact Name if present	    	    
    if (getContactName(context, number) != null) {
    	contactname = getContactName(context, number);
    }
    
       //create json object to send	            
       try {        
       	jobject.put("name", contactname);
       	jobject.put("number", number);
		jobject.put("message", sms.getMessageBody());
	} catch (JSONException e) {
		e.printStackTrace();
	}
       
       startServiceCommand(context, "SMS", jobject.toString());		
}
 
开发者ID:screenfreeze,项目名称:deskcon-android,代码行数:25,代码来源:EventBroadcastReceiver.java

示例15: 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


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