编程方式发送短信的Andr​​oid(不接收状态) [英] Programatically send SMS Android (Not receiving status)

查看:126
本文介绍了编程方式发送短信的Andr​​oid(不接收状态)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 http://mobiforge.com/developing/story/sms-messaging -Android code除非我改变的事实字例如字:

 进口android.telephony.gsm.SmsManager;
 

 进口android.telephony.SmsManager;
 

该短信​​发送精细不过,我没有得到,它被送到了TOAST消息(发送到网络)。我想短信融入我的应用程序,这是非常重要的。我相信这是可以做到,因为要不然股票SMS应用程序知道何时停止显示发送圈。有关code部分如下:

  // ---当短信已发送---
    registerReceiver(新BroadcastReceiver的(){
        @覆盖
        公共无效的onReceive(背景为arg0,意图ARG1){
            开关(的getResult code())
            {
                案例Activity.RESULT_OK:
                    Toast.makeText(getBaseContext(),短信发送
                            Toast.LENGTH_SHORT).show();
                    打破;
                案例SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                    Toast.makeText(getBaseContext(),一般故障,
                            Toast.LENGTH_SHORT).show();
                    打破;
                案例SmsManager.RESULT_ERROR_NO_SERVICE:
                    Toast.makeText(getBaseContext(),无服务,
                            Toast.LENGTH_SHORT).show();
                    打破;
                案例SmsManager.RESULT_ERROR_NULL_PDU:
                    Toast.makeText(getBaseContext(),空的PDU,
                            Toast.LENGTH_SHORT).show();
                    打破;
                案例SmsManager.RESULT_ERROR_RADIO_OFF:
                    Toast.makeText(getBaseContext(),无线电关
                            Toast.LENGTH_SHORT).show();
                    打破;
            }
        }
    },新的IntentFilter(发送));

    // ---当SMS已交付---
    registerReceiver(新BroadcastReceiver的(){
        @覆盖
        公共无效的onReceive(背景为arg0,意图ARG1){
            开关(的getResult code())
            {
                案例Activity.RESULT_OK:
                    Toast.makeText(getBaseContext(),SMS递送,
                            Toast.LENGTH_SHORT).show();
                    打破;
                案例Activity.RESULT_CANCELED:
                    Toast.makeText(getBaseContext(),短信未交付,
                            Toast.LENGTH_SHORT).show();
                    打破;
            }
        }
    },新的IntentFilter(交付));
 

我使用的是果冻豆ROM,但我相信我刚才测试了这个相同的网段上姜饼和ICS具有相同的结果。先后在API变化或者是有问题的样本?我在Sasmsung GSIII测试有没有什么帮助。我的老测试是在一个史诗。

解决方案

对于现在的人有这个问题,如果你正在测试这个在Android 4.4或更高版本,将无法正常工作,除非你的应用程序是默认的短信应用程序。

从文档 -

  
    

与Android 4.4开始,系统设置,让用户选择一个默认短信应用程序。一旦选定,只有默认的短信应用程序是能够写入SMS提供,仅默认的短信应用程序接收SMS_DELIVER_ACTION广播,当用户接收到一个短信或当用户收到一条彩信WAP_PUSH_DELIVER_ACTION播出。默认SMS应用程序负责撰写详细信息SMS提供其接收或发送新邮件时。

  

请参阅这里

I am using http://mobiforge.com/developing/story/sms-messaging-android code example word for word except for the fact that I changed:

import android.telephony.gsm.SmsManager;

to:

import android.telephony.SmsManager;

The SMS is sending fine however I am not getting the TOAST message that it was delivered (sent to the network). I am trying to integrate SMS into my application and this is important. I am sure this can be done because how else would the stock SMS app know when to stop displaying the "sending circle". The relevant code section is as follows:

   //---when the SMS has been sent---
    registerReceiver(new BroadcastReceiver(){
        @Override
        public void onReceive(Context arg0, Intent arg1) {
            switch (getResultCode())
            {
                case Activity.RESULT_OK:
                    Toast.makeText(getBaseContext(), "SMS sent", 
                            Toast.LENGTH_SHORT).show();
                    break;
                case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                    Toast.makeText(getBaseContext(), "Generic failure", 
                            Toast.LENGTH_SHORT).show();
                    break;
                case SmsManager.RESULT_ERROR_NO_SERVICE:
                    Toast.makeText(getBaseContext(), "No service", 
                            Toast.LENGTH_SHORT).show();
                    break;
                case SmsManager.RESULT_ERROR_NULL_PDU:
                    Toast.makeText(getBaseContext(), "Null PDU", 
                            Toast.LENGTH_SHORT).show();
                    break;
                case SmsManager.RESULT_ERROR_RADIO_OFF:
                    Toast.makeText(getBaseContext(), "Radio off", 
                            Toast.LENGTH_SHORT).show();
                    break;
            }
        }
    }, new IntentFilter(SENT));

    //---when the SMS has been delivered---
    registerReceiver(new BroadcastReceiver(){
        @Override
        public void onReceive(Context arg0, Intent arg1) {
            switch (getResultCode())
            {
                case Activity.RESULT_OK:
                    Toast.makeText(getBaseContext(), "SMS delivered", 
                            Toast.LENGTH_SHORT).show();
                    break;
                case Activity.RESULT_CANCELED:
                    Toast.makeText(getBaseContext(), "SMS not delivered", 
                            Toast.LENGTH_SHORT).show();
                    break;                        
            }
        }
    }, new IntentFilter(DELIVERED));          

I am using a Jelly Bean ROM but I believe I tested this same segment a while ago on Gingerbread and ICS with the same results. Has the API changed or is there an issue with the sample? I am testing on a Sasmsung GSIII if that helps. My old tests were on an Epic.

解决方案

For anyone having this problem now, if you're testing this on Android 4.4 or later, it will not work unless your app is the default SMS app.

From the docs -

Beginning with Android 4.4, the system settings allow users to select a "default SMS app." Once selected, only the default SMS app is able to write to the SMS Provider and only the default SMS app receives the SMS_DELIVER_ACTION broadcast when the user receives an SMS or the WAP_PUSH_DELIVER_ACTION broadcast when the user receives an MMS. The default SMS app is responsible for writing details to the SMS Provider when it receives or sends a new message.

See here.

这篇关于编程方式发送短信的Andr​​oid(不接收状态)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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