在收到短信创建警报对话框 [英] create alert dialog on receiving sms

查看:164
本文介绍了在收到短信创建警报对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建为Android应用程序一个它发送使用网关短信,如way2sms.com,fullonsms.com,我已经成功地从这些网关发送消息,现在我想采取另一个步骤,即短信发送报告。我对我将如何做到这一点的基本思想。当我将发送短信通过后,用户选择的号码,我将发送一个SMS回用户提供用于例如一些格式化的文本SMSDELIVERYREPORT。我想要做的是,当用户收到这样的消息,而不是正常的通知,我们得到当我们收到正常的短信,一个警告对话框中创建应用程序说消息传递成功。请指导我实现这个任务。以及如何我可以保证这个消息不会在用户的正常收件箱中去了。

I am creating a app for android which sends sms using gateways like "way2sms.com", "fullonsms.com", i have succeeded in sending messages from those gateways, now i want to take another step, i.e "SMS DELIVERY REPORT". I have a basic idea about how will i do this. When i will send sms to the number selected by the user after that i will send one sms back to user with some formatted text for e.g. "SMSDELIVERYREPORT". What i want to do is that when the user receives such message instead of normal notification which we get when we receive normal sms, the application of create a Alert Dialog saying "Message successfully delivered." Please guide me in fulfilling this task. and also how can i make sure that this messages do not go in users normal message inbox.

推荐答案

这code将涵盖您的SMS的所有可能的情况下发送。

This code would cover all the possible cases of your SMS sending.

private void sendSMS(String phoneNumber, String message)
{        
    String SENT = "SMS_SENT";
    String DELIVERED = "SMS_DELIVERED";

    PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,
        new Intent(SENT), 0);

    PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
        new Intent(DELIVERED), 0);

    //---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));        

    SmsManager sms = SmsManager.getDefault();
    sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);        
}

这是href=\"http://mobiforge.com/developing/story/sms-messaging-android\" rel=\"nofollow\">伟大的教程一个

And here is a great tutorial!

这篇关于在收到短信创建警报对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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