我想检查邮件是否已发送。 如果由于蜂窝信号问题而没有发送消息,我会举杯说“#34;没有simcard信号再次尝试"
这是我在MainActivity.java中的代码
public void sendSMSMessage(String to, String message) {
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(to, null, message, null, null);
Toast.makeText(getApplicationContext(), "Sent!", Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "Failed!", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
感谢。阿迪奥斯
答案 0 :(得分:0)
@Override
protected void onResume() {
super.onResume();
registerReceiver(smsSentReceiver, new IntentFilter("android.provider.Telephony.SMS_SENT"));
}
@Override
protected void onPause() {
super.onPause();
unregisterReceiver(smsSentReceiver);
}
private final BroadcastReceiver smsSentReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(getApplicationContext(), "Sent!", Toast.LENGTH_LONG).show();
}
}