吐司显示问题+ android

时间:2011-03-09 12:44:43

标签: android toast

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

Plzz帮助我...

1 个答案:

答案 0 :(得分:1)

arg0代替getBaseContext()