我有一個關於我創建的短信應用程序的問題(學習目的)。SMSManager和待定意圖
在發送短信我想有一個敬酒的消息顯示,一旦它已經deleivered(或沒有)
問題是一旦我點擊發送我想關閉該活動,但仍然有吐司消息(在這種情況下)出現給我的信息。
由於我是新手,我不知道如何去做這件事。我所做的一切都是等待信息通過,設置信息然後關閉活動。
private void sendSMS() {
PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED), PendingIntent.FLAG_NO_CREATE);
deliverActivity = new BroadcastReceiver() {
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode()) {
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "SMS delivered",
Toast.LENGTH_LONG).show();
finishActivity();
break;
case Activity.RESULT_CANCELED:
Toast.makeText(getBaseContext(), "SMS not delivered",
Toast.LENGTH_LONG).show();
finishActivity();
break;
}
}
};
registerReceiver(deliverActivity, new IntentFilter(DELIVERED));
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(toNo, null, toSend.getText().toString(), deliveredPI, null);
ContentValues values = new ContentValues();
values.put("address", toNo);
values.put("body", toSend.getText().toString());
this.getContentResolver().insert(Uri.parse("content://sms/sent"), values);
}
private void finishActivity() {
unregisterReceiver(deliverActivity);
Intent intent = new Intent();
setResult(123, intent);
finish();
}
我確定這是可能的,甚至可能將其傳遞給另一個活動。
這聽起來有些迂腐,但它讓我學習新的做事方式...所以如果任何人都可以指出我的方向是正確的,那就太棒了。
謝謝!
感謝您的鏈接,現在看看 – 2012-03-01 21:48:27
看看,我可以得到敬酒出現(如在調用它),然後我完成活動......從我可以告訴這是一樣的開始一個線程對於吐司消息,然後讓該線程在毫秒數的吐司消息結束之後進入睡眠狀態......否? – 2012-03-02 05:20:57