`

获得手机中心号(服务号)

 
阅读更多
package lab.sodino.servicecenteraddress;

import android.app.Activity;

import android.app.PendingIntent;

import android.content.BroadcastReceiver;

import android.content.Context;

import android.content.Intent;

import android.content.IntentFilter;

import android.os.Bundle;

import android.telephony.gsm.SmsManager;

import android.telephony.gsm.SmsMessage;

import android.view.Gravity;

import android.view.View;

import android.widget.Button;

import android.widget.LinearLayout;

import android.widget.TextView;

import android.widget.LinearLayout.LayoutParams;

public class ServiceCenterAddressAct extends Activity {

        private static final String ACTION_SMS_SEND = "lab.sodino.sms.send";

        private static final String ACTION_SMS_DELIVERY = "lab.sodino.sms.delivery";

        private static final String ACTION_SMS_RECEIVER = "android.provider.Telephony.SMS_RECEIVED";

        private TextView serviceCenterAddressText;

        private SMSReceiver sendReceiver;

        private SMSReceiver deliveryReceiver;

        private SMSReceiver smsReceiver;

        /** Called when the activity is first created. */

        @Override

        public void onCreate(Bundle savedInstanceState) {

                super.onCreate(savedInstanceState);

                LinearLayout.LayoutParams layParams = new LinearLayout.LayoutParams(

                                LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);

                LinearLayout linearLay = new LinearLayout(this);

                linearLay.setOrientation(LinearLayout.VERTICAL);

                linearLay.setLayoutParams(layParams);

                TextView textView = new TextView(this);

                textView.setBackgroundColor(0xffffffff);

                textView.setTextColor(0xff0000ff);

                textView.setTextSize(20);

                textView.setText("点击发送按钮将发送自定义字符串至10086");

                textView.setGravity(Gravity.CENTER);

                linearLay.addView(textView);

                Button btnSend = new Button(this);

                // LinearLayout.LayoutParams btnParams = new LinearLayout.LayoutParams(

                // LinearLayout.LayoutParams.FILL_PARENT,

                // LinearLayout.LayoutParams.WRAP_CONTENT);

                btnSend.setText("发送");

                btnSend.setOnClickListener(new Button.OnClickListener() {

                        public void onClick(View v) {

                                serviceCenterAddressText.setText("正在等待发送短信...");

                                sendSms();

                        }

                });

                linearLay.addView(btnSend);

                serviceCenterAddressText = new TextView(this);

                serviceCenterAddressText.setText("正在等待发送短信...");

                serviceCenterAddressText.setBackgroundColor(0xffffffff);

                serviceCenterAddressText.setTextColor(0xff0000ff);

                serviceCenterAddressText.setTextSize(20);

                serviceCenterAddressText.setGravity(Gravity.LEFT);

                linearLay.addView(serviceCenterAddressText);

                setContentView(linearLay);

                // 注册send

                sendReceiver = new SMSReceiver();

                IntentFilter sendFilter = new IntentFilter(ACTION_SMS_SEND);

                registerReceiver(sendReceiver, sendFilter);

                // 注册delivery

                deliveryReceiver = new SMSReceiver();

                IntentFilter deliveryFilter = new IntentFilter(ACTION_SMS_DELIVERY);

                registerReceiver(deliveryReceiver, deliveryFilter);

                // 注册接收下行receiver

                smsReceiver = new SMSReceiver();

                IntentFilter receiverFilter = new IntentFilter(ACTION_SMS_RECEIVER);

                registerReceiver(smsReceiver, receiverFilter);

        }

        protected void onPause() {

                unregisterReceiver(sendReceiver);

                unregisterReceiver(deliveryReceiver);

                unregisterReceiver(smsReceiver);

        }

        private void sendSms() {

                String smsBody = "lab.sodino.sms.test";

                String smsAddress = "10086";

                SmsManager smsMag = SmsManager.getDefault();

                Intent sendIntent = new Intent(ACTION_SMS_SEND);

                PendingIntent sendPI = PendingIntent.getBroadcast(this, 0, sendIntent,

                                0);

                Intent deliveryIntent = new Intent(ACTION_SMS_DELIVERY);

                PendingIntent deliveryPI = PendingIntent.getBroadcast(this, 0,

                                deliveryIntent, 0);

                smsMag.sendTextMessage(smsAddress, null, smsBody, sendPI, deliveryPI);

        }

        public class SMSReceiver extends BroadcastReceiver {

                public void onReceive(Context context, Intent intent) {

                        String actionName = intent.getAction();

                        int resultCode = getResultCode();

                        if (actionName.equals(ACTION_SMS_SEND)) {

                                switch (resultCode) {

                                case Activity.RESULT_OK:

                                        serviceCenterAddressText

                                                        .append("\n[Send]SMS Send:Successed!");

                                        break;

                                case SmsManager.RESULT_ERROR_GENERIC_FAILURE:

                                        serviceCenterAddressText

                                                        .append("\n[Send]SMS Send:RESULT_ERROR_GENERIC_FAILURE!");

                                        break;

                                case SmsManager.RESULT_ERROR_NO_SERVICE:

                                        serviceCenterAddressText

                                                        .append("\n[Send]SMS Send:RESULT_ERROR_NO_SERVICE!");

                                        break;

                                case SmsManager.RESULT_ERROR_NULL_PDU:

                                        serviceCenterAddressText

                                                        .append("\n[Send]SMS Send:RESULT_ERROR_NULL_PDU!");

                                        break;

                                case SmsManager.RESULT_ERROR_RADIO_OFF:

                                        break;

                                }

                        } else if (actionName.equals(ACTION_SMS_DELIVERY)) {

                                switch (resultCode) {

                                case Activity.RESULT_OK:

                                        serviceCenterAddressText

                                                        .append("\n[Delivery]SMS Delivery:Successed!");

                                        break;

                                case SmsManager.RESULT_ERROR_GENERIC_FAILURE:

                                        serviceCenterAddressText

                                                        .append("\n[Delivery]SMS Delivery:RESULT_ERROR_GENERIC_FAILURE!");

                                        break;

                                case SmsManager.RESULT_ERROR_NO_SERVICE:

                                        serviceCenterAddressText

                                                        .append("\n[Delivery]SMS Delivery:RESULT_ERROR_NO_SERVICE!");

                                        break;

                                case SmsManager.RESULT_ERROR_NULL_PDU:

                                        serviceCenterAddressText

                                                        .append("\n[Delivery]SMS Delivery:RESULT_ERROR_NULL_PDU!");

                                        break;

                                case SmsManager.RESULT_ERROR_RADIO_OFF:

                                        serviceCenterAddressText

                                                        .append("\n[Delivery]SMS Delivery:RESULT_ERROR_RADIO_OFF!");

                                        break;

                                }

                                serviceCenterAddressText.append("\n正在等待下行短信...");

                        } else if (actionName.equals(ACTION_SMS_RECEIVER)) {

                                System.out.println("[Sodino]result = " + resultCode);

                                Bundle bundle = intent.getExtras();

                                if (bundle != null) {

                                        Object[] myOBJpdus = (Object[]) bundle.get("pdus");

                                        SmsMessage[] messages = new SmsMessage[myOBJpdus.length];

                                        for (int i = 0; i < myOBJpdus.length; i++) {

                                                messages[i] = SmsMessage

                                                                .createFromPdu((byte[]) myOBJpdus[i]);

                                        }

                                        SmsMessage message = messages[0];

                                        serviceCenterAddressText.append("\n短信服务中心号码为:"

                                                        + message.getServiceCenterAddress());

                                }

                        }

                }

        }

}
分享到:
评论

相关推荐

    python获取微信小程序手机号并绑定遇到的坑

    组件 open-type 的值设置为 getPhoneNumber,当用户点击并同意之后,可以通过 bindgetphonenumber 事件回调获取到微信服务器返回的加密数据, 然后在第三方服务端结合 session_key 以及 app_id 进行解密获取手机号。...

    (安卓)Android获取本机手机号及服务运营商

    获取本机手机号以及服务运营商并显示的DEMO,代码简洁明了,供大家学习交流

    支付宝小程序-获取会员手机号

    1、适用于uniapp开发支付宝小程序 2、 组件 open-type=getAuthorize ,用于授权 3、当用户点击并同意之后,可以通过my.getPhoneNumber() 接口获取到支付宝服务器返回的加密数据

    根据ip和手机号码获取地址的webService

    根据ip获取服务器地址,和根据手机号码获取号码归属地和卡类型和区号,webservice

    手机号码归属地查询软件 v6.7.1.1113 免费版.zip

    手机号码归属地查询支持全国最新的15X号段...手机号码归属地查询为一款免费软件,但如果您在业务工作上对手机号码数据库有一定需要,您可根据您的情况选择注册会员版查询软件,或者直接与众易网合作,获得完整数据库。

    Delphi开发安卓APP获取手机信息的详细代码

    Delphi D10.X安卓APP开发中获取硬件信息及手机号,完整代码,安卓5.1到10可使用。压缩包里有详细使用说明

    微信小程序利用云函数获取手机号码

    小程序获取手机号码方式  一、取到加密数据,然后提交到服务器解密, 二、获取到 cloudID,用云函数, 优点:直接获取原始数据,节省服务器资源 1.xml &lt;button class="gettel" open-type="getPhoneNumber" ...

    绑定手机号登录-VUE模板 UNIAPP模板 布局、样式、JS分离

    绑定手机号登录-VUE模板 UNIAPP模板 布局、样式、JS分离 帮助 手机号 认证服务由中国联通提供 本机号码一键登录 其他手机号码登录 我已阅读并同意用户协议和隐私政策以及《中国联通认证服务条款》 其他方式...

    unity c#手机短信验证码登陆注册

    unity c#,实现手机号短信验证码登录注册功能,文中已写好代码,可直接替换自己的id和密钥后直接使用,注册地址在文中,内容包含,第三方短信验证码平台的接口代码,已写好,具体验证码调用接口代码,已写好,直接...

    Android 身份证号 手机号码归属地查询源码包.rar

     DeviceHelper 定义了一个设备信息类 主要功能有获取尺寸 读取手机号  HttpClientHelper 定义了一个服务请求类,实现与服务器的交流。  HttpException 继承 Exception 实现了输出异常信息  HttpPostParameter ...

    微信小程序获取用户手机号码(后台php版)

    然后结合iv和encryptedData解密出微信用户手机号码【操作步骤】第1步:wx.login获取code第2步:传递code到服务器,获取session_key和openid第3步:参考官方文档getPhoneNumber,获取iv和encryptedData第...获取手机号码

    微信小程序获取用户手机号码(后台asp版)

    前端微信小程序获取code,后台使用asp获取session_key和openid;然后结合iv和encryptedData解密出微信用户手机号码【操作步骤】第1步:wx.login获取code第2步:传递code到服务器,获取session_key和...获取手机号码

    android手机验证码的获取

    android手机验证码的获取,这个demo只做好了客户端客户端的处理,所以发送验证码的手机号是本机,连接服务器只需调整参数即可。

    微信小程序获取用户手机号码(后台jsp、java版)

    前端微信小程序获取code,后台使用asp获取session_key和openid;然后结合iv和encryptedData解密出微信用户手机号码【操作步骤】第1步:wx.login获取code第2步:传递code到服务器,获取session_key和...获取手机号码

    Android 获取移动网络及SIM卡运营商信息.rar

    Android 获取移动网络及SIM卡运营商信息,可获取到SIM卡国别、SIM卡序列号、SIM卡状态、运营商代号、手机制式等信息。...//获取手机制式  listValues.add(tm.getCellLocation().toString());//获取设备当前位置

    摩安手机卫士Android版本

    1、新增安全诊断功能:扫面各类恶意软件、恶意行为,自动判断应用程序是否存在偷发短信、盗拨电话、获取手机IMIE号码、获取手机号码等各类恶意行为; 2、业界唯一支持motoXT800双网双待机型; 3、支持联想LePhone和...

    艺帆仿百度云手机简约手机官方网站模板V1.8

    所谓的“云手机”其实就是深度结合了网络服务的智能手机,这类手机凭借自带的系统以及厂商架设的网络终端可以通过网络实现众多的功能,网络在这些手机身上不再仅仅只是用来浏览内容,网络是“云手机”获取服务的来源...

Global site tag (gtag.js) - Google Analytics