我真的对一个问题感到困惑。准确地说,每次打开应用程序时,我都会向一个号码(从网络服务获取)发送一条短信。代码片段如下:
private void sendSMSToDevices() {
try {
String SENT = "SentSMSActivity";
String DELIVERED = "ReceivedSMSActivity";
PendingIntent sentPI = PendingIntent.getBroadcast(context, 0, new Intent(SENT), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(context, 0, new Intent(DELIVERED), 0);
SmsManager smsManager = SmsManager.getDefault();
if (flagFirstTime) {
smsManager.sendTextMessage(phone_one, null, message_one, sentPI, deliveredPI);
} else {
smsManager.sendTextMessage(phone_two, null, message_two, sentPI, deliveredPI);
}
// Toast.makeText(getApplicationContext(), "SMS Sent!",
// Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "SMS faild, please try again later!", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
清单文件中的使用权限为::
android.permission.SEND_SMS
android.permission.ACCESS_NETWORK_STATE
android.permission.INTERNET
android.permission.RECEIVE_BOOT_COMPLETED
每次我打开应用程序时,它都会在发送短信之前显示一条警报,说“(my_App_Name)想向(phone_nember)发送一条消息”
我从来没有在我的代码中放置任何警报。为什么会这样?请帮忙。