在Android中我应该如何让短信发送者的电话号码吗? [英] In android how should i get phone number of sms sender?

查看:88
本文介绍了在Android中我应该如何让短信发送者的电话号码吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android中我应该如何让短信发送者的电话号码吗?

我做的应用程序,发送短信,但需要钱费了,这样我可以发送短信,不收取钱?请告诉我

I make application which sends sms but takes money charges for that, so can i send sms without charging money? please tell me

推荐答案

要发送短信不花钱,如果你执行任何免费的短信网关是唯一可能的。基于你是哪个国家,你会发现任何免费的短信网关,并试图找到他们所提供的任何Web服务或API。使用撰写code,你就可以发短信免费。使 相信这需要您的手机上的互联网连接。

To send SMS without Spending Money is only possible if you implement any FREE SMS GATEWAY. Based on what country you are, you will find any FREE SMS GATEWAY and try to find any web services or API they are providing. Write a code using that and you will be able to send SMS for FREE. Make sure this required an internet connection on your phone.

如果您实现一个广播接收器的接收短信在下面这种情况下是code将跟踪imcoming短信给你的留言和发送者号码。

If you implement a BroadCast Receiver for Incoming SMS in that case following is the code which will track your imcoming SMS and will give you the Message and Sender Number.

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.gsm.SmsMessage;
import android.widget.Toast;

public class SmsReceiver extends BroadcastReceiver
{
    @Override
    public void onReceive(Context context, Intent intent) 
    {
        //---get the SMS message passed in---
        Bundle bundle = intent.getExtras();        
        SmsMessage[] msgs = null;
        String str = "";            
        if (bundle != null)
        {
            //---retrieve the SMS message received---
            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 += "SMS from " + msgs[i].getOriginatingAddress();                     
                str += " :";
                str += msgs[i].getMessageBody().toString();
                str += "\n";        
            }
            //---display the new SMS message---
            Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
        }                         
    }
}

这篇关于在Android中我应该如何让短信发送者的电话号码吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆