toast显示问题+安卓

发布于 2024-10-21 04:23:56 字数 3392 浏览 2 评论 0原文

Toast 正在模拟器上显示,即“短信已发送”等。

但它没有在 HTC 设备上显示。

    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) 
        {      
            String idtochange= Integer.toString(prefName);
            switch (getResultCode())
            {                   
                case Activity.RESULT_OK:                        
                    Toast.makeText(getBaseContext(), "SMS sent",Toast.LENGTH_LONG).show();
                    con.onUpdateSet("master_table", "remark", "result_ok", new String[] {"msg_id"},new String[] {idtochange});
                    break;

                case SmsManager.RESULT_ERROR_GENERIC_FAILURE:                       
                    Toast.makeText(getBaseContext(), "Generic failure",Toast.LENGTH_SHORT).show();
                    con.onUpdateSet("master_table", "remark", "generic_failure", new String[] {"msg_id"},new String[] {idtochange});
                    break;

                case SmsManager.RESULT_ERROR_NO_SERVICE:
                    Toast.makeText(getBaseContext(), "No service",Toast.LENGTH_SHORT).show();
                    con.onUpdateSet("master_table", "remark", "no_serivce", new String[] {"msg_id"},new String[] {idtochange});
                    break;

                case SmsManager.RESULT_ERROR_NULL_PDU:
                    Toast.makeText(getBaseContext(), "Null PDU",Toast.LENGTH_SHORT).show();
                    con.onUpdateSet("master_table", "remark", "null_pdu", new String[] {"msg_id"},new String[] {idtochange});
                    break;                    

                case SmsManager.RESULT_ERROR_RADIO_OFF:
                    Toast.makeText(getBaseContext(), "Radio off",Toast.LENGTH_SHORT).show();
                    con.onUpdateSet("master_table", "remark", "radio_off", new String[] {"msg_id"},new String[] {idtochange});
                    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_LONG).show();
                    break;                    

                case Activity.RESULT_CANCELED:
                    Toast.makeText(getBaseContext(), "SMS not delivered",Toast.LENGTH_SHORT).show();
                    break;                      
            }           
        }        

    }, new IntentFilter(DELIVERED));

    SmsManager sms = SmsManager.getDefault();
    System.out.println("contactsssss"+phoneNumber);
    sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI); 

请帮我解决这个问题...

Toast is displaying on emulator i.e "SMS sent".etc.

but it is not displaying on HTC device.

    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) 
        {      
            String idtochange= Integer.toString(prefName);
            switch (getResultCode())
            {                   
                case Activity.RESULT_OK:                        
                    Toast.makeText(getBaseContext(), "SMS sent",Toast.LENGTH_LONG).show();
                    con.onUpdateSet("master_table", "remark", "result_ok", new String[] {"msg_id"},new String[] {idtochange});
                    break;

                case SmsManager.RESULT_ERROR_GENERIC_FAILURE:                       
                    Toast.makeText(getBaseContext(), "Generic failure",Toast.LENGTH_SHORT).show();
                    con.onUpdateSet("master_table", "remark", "generic_failure", new String[] {"msg_id"},new String[] {idtochange});
                    break;

                case SmsManager.RESULT_ERROR_NO_SERVICE:
                    Toast.makeText(getBaseContext(), "No service",Toast.LENGTH_SHORT).show();
                    con.onUpdateSet("master_table", "remark", "no_serivce", new String[] {"msg_id"},new String[] {idtochange});
                    break;

                case SmsManager.RESULT_ERROR_NULL_PDU:
                    Toast.makeText(getBaseContext(), "Null PDU",Toast.LENGTH_SHORT).show();
                    con.onUpdateSet("master_table", "remark", "null_pdu", new String[] {"msg_id"},new String[] {idtochange});
                    break;                    

                case SmsManager.RESULT_ERROR_RADIO_OFF:
                    Toast.makeText(getBaseContext(), "Radio off",Toast.LENGTH_SHORT).show();
                    con.onUpdateSet("master_table", "remark", "radio_off", new String[] {"msg_id"},new String[] {idtochange});
                    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_LONG).show();
                    break;                    

                case Activity.RESULT_CANCELED:
                    Toast.makeText(getBaseContext(), "SMS not delivered",Toast.LENGTH_SHORT).show();
                    break;                      
            }           
        }        

    }, new IntentFilter(DELIVERED));

    SmsManager sms = SmsManager.getDefault();
    System.out.println("contactsssss"+phoneNumber);
    sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI); 

Plzz help me for this...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寂寞清仓 2024-10-28 04:23:56

使用 arg0 代替 getBaseContext()

Put arg0 instead of getBaseContext().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文