在广播接收器,的getResult code()总是返回-1短信发送并交付行动 [英] In BroadcastReceiver, getResultCode() always returns -1 for SMS sent and delivered actions

查看:1026
本文介绍了在广播接收器,的getResult code()总是返回-1短信发送并交付行动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

随着大多数人我猜,我从 HTTP导出我的短信处理code ://mobiforge.com/developing/story/sms-messaging-android 。我想抓住的发送和传递信息的广播,此code(对于发送的消息):

  appContext.registerReceiver(新广播接收器(){
            @覆盖
            公共无效的onReceive(上下文为arg0,ARG1意向){
                Log.i(调试,
                        我的嵌入式接收器
                                +将String.valueOf(的getResult code()));
            }
        },新的IntentFilter(iam.applications.SmsReceiver.SMS_SENT));

这总是导致的getResult code()返回值-1,即使成功发送短信。我不知道的另一种方式告诉我的短信是否发送或没有。

我也子类广播接收器,看看是否有什么差别,但事实并非如此。 -1总是返回:

  @覆盖
公共无效的onReceive(上下文的背景下,意图意图){
    字符串行动= intent.getAction();    Log.i(调试,
            结果code中的onReceive:+将String.valueOf(的getResult code()));
}

我对的PendingIntent的创建看起来像这样(从for循环片段处理长短信的部分):

 意图sentIntent =新意图(
                iam.applications.SmsReceiver.SMS_SENT);
        sentIntent.putExtra(SmsHandler.PHONE_NUMBER,phoneNumber的);
        sentIntent.putExtra(SmsHandler.MESSAGE,消息);
        sentPIArray.add(PendingIntent.getBroadcast(appContext,
                getTimeInMillis()(int)的Calendar.getInstance(),sentIntent,
                PendingIntent.FLAG_UPDATE_CURRENT));


解决方案

我是一个大傻瓜:

  //字段描述符#14我
公共静态最终诠释RESULT_OK = -1;

Following most people I guess, I am deriving my SMS handling code from http://mobiforge.com/developing/story/sms-messaging-android. I am trying to catch the broadcasts for sent and delivered messages, with this code (for sent messages):

        appContext.registerReceiver(new BroadcastReceiver() {
            @Override
            public void onReceive(Context arg0, Intent arg1) {
                Log.i("Debug",
                        "My embedded receiver: "
                                + String.valueOf(getResultCode()));
            }
        }, new IntentFilter("iam.applications.SmsReceiver.SMS_SENT"));

This always results in getResultCode() returning a value of -1, even when the SMS is successfully sent. I don't know of another way to tell whether my SMS was sent or not.

I have also subclassed BroadcastReceiver to see if that makes any difference, but it does not. -1 is always returned:

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();

    Log.i("Debug",
            "Result code in onReceive: " + String.valueOf(getResultCode()));
}

My creation of the PendingIntent looks like this (snippet from a for-loop for processing parts of long SMS messages):

        Intent sentIntent = new Intent(
                "iam.applications.SmsReceiver.SMS_SENT");
        sentIntent.putExtra(SmsHandler.PHONE_NUMBER, phoneNumber);
        sentIntent.putExtra(SmsHandler.MESSAGE, message);
        sentPIArray.add(PendingIntent.getBroadcast(appContext,
                (int) Calendar.getInstance().getTimeInMillis(), sentIntent,
                PendingIntent.FLAG_UPDATE_CURRENT));

解决方案

I'm a big idiot:

// Field descriptor #14 I
public static final int RESULT_OK = -1;

这篇关于在广播接收器,的getResult code()总是返回-1短信发送并交付行动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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