对系统对话框 SmsManager 作出反应
React to systemdialog SmsManager
我的应用程序发送这样的文本:
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(NUMBER, null, "sms message", null, null);
在向用户发送之前,系统会显示一个他必须确认的系统对话框。
"App would like to send a message to 000"
我想对用户取消该对话框的情况做出反应。有办法吗?
找到了解决我的问题的方法。如果用户取消对话框,"sent" PendingIntent
将失败。
String SENT = "sent";
Intent sentIntent = new Intent(SENT);
PendingIntent sentPI = PendingIntent.getBroadcast(
getApplicationContext(), 0, sentIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String result = "";
switch (getResultCode()) {
case Activity.RESULT_OK:
result = "Transmission successful";
break;
case 5: // SmsManager.RESULT_ERROR_LIMIT_EXCEEDED
// The static variable is hidden.
// The user denied sending the sms
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
result = "Transmission failed";
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
result = "Radio off";
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
result = "No PDU defined";
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
result = "No service";
break;
}
Log.i("debug", result);
}
}, new IntentFilter(SENT));
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(SMS_NUMBER, null, MESSAGE, sentPI, null);
我的应用程序发送这样的文本:
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(NUMBER, null, "sms message", null, null);
在向用户发送之前,系统会显示一个他必须确认的系统对话框。
"App would like to send a message to 000"
我想对用户取消该对话框的情况做出反应。有办法吗?
找到了解决我的问题的方法。如果用户取消对话框,"sent" PendingIntent
将失败。
String SENT = "sent";
Intent sentIntent = new Intent(SENT);
PendingIntent sentPI = PendingIntent.getBroadcast(
getApplicationContext(), 0, sentIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String result = "";
switch (getResultCode()) {
case Activity.RESULT_OK:
result = "Transmission successful";
break;
case 5: // SmsManager.RESULT_ERROR_LIMIT_EXCEEDED
// The static variable is hidden.
// The user denied sending the sms
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
result = "Transmission failed";
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
result = "Radio off";
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
result = "No PDU defined";
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
result = "No service";
break;
}
Log.i("debug", result);
}
}, new IntentFilter(SENT));
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(SMS_NUMBER, null, MESSAGE, sentPI, null);