[英]Android: Display Toast after sending SMS
我想按下發送按鈕后彈出一些文本。 現在,我已經找到了使用其他方法時可以做到這一點的方法,但這是學校的作業,因此我想使其保持簡單並與當前水平保持一致。
這就是我所擁有的:
public void onClick(View arg0) {
if(arg0.equals(sms)) {
Intent c = new Intent(Intent.ACTION_VIEW);
Uri pho = Uri.parse("smsto:" +text.getText().toString());
c.setData(pho);
c.putExtra("sms_body", "Text");
startActivity(c);
我添加以下行:
Toast.makeText(this, "SMS sent", Toast.LENGTH_LONG).show();
這使得Toast立即出現,並且在按下發送按鈕之前。
使用我當前的代碼發送后,是否有辦法讓它出現?
您可以使用廣播接收器檢查是否已發送消息或接收到傳入消息,並且在發送消息后,接收器會監聽操作,並且可以執行Toast展示操作
這里有一個例子向您展示了實現它的步驟
registerReceiver(new BroadcastReceiver() {
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode()) {
case Activity.RESULT_OK:
//code is here
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
break;
}
}
}, new IntentFilter(SENT));
我想這就是你想要的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.