gpt4 book ai didi

android - Android 发送短信前提示

转载 作者:行者123 更新时间:2023-11-29 17:52:19 24 4
gpt4 key购买 nike

我是 Android 的新手,我正在尝试通过 Android 应用程序发送短信。我需要这样,如果消息包含单词“MYSELF”提示用户他们是否要继续发送 SMS 我的方法是:

public void sendSmsByManager() {

try {

// Get the default instance of the SmsManager

SmsManager smsManager = SmsManager.getDefault();

smsManager.sendTextMessage(phoneNumber.getText().toString(),
null,
smsBody.getText().toString(),
null,
null);
//If the SMS Contains the WORD MYSELF Prompt the User If they Want to send the SMS

Toast.makeText(getApplicationContext(),
"Your sms has successfully sent!",

Toast.LENGTH_LONG).show();

} catch (Exception ex) {

Toast.makeText(getApplicationContext(), "Your sms has failed...",

Toast.LENGTH_LONG).show();

ex.printStackTrace();

}

}

我怎样才能做到这一点?

最佳答案

创建警报确认样式对话框。

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Some Message");
builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//send text
}
});
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//discard text
}
});

AlertDialog dialog = builder.create();
dialog.show();

关于android - Android 发送短信前提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22045636/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com