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);
请帮我解决这个问题...
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
arg0
代替getBaseContext()
。Put
arg0
instead ofgetBaseContext()
.