SMSManager和意图之前 [英] SMSManager and Pending Intent
问题描述
我有一个关于短信应用程序,我创建(学习目的)的问题。
I have a question about an SMS app i am creating (learning purposes).
在发送短信我想有一个敬酒的消息显示一旦被deleivered(或没有)
On sending an SMS i would like to have a toast message appear once it has been deleivered (or not)
问题是,一旦我击中发送我想关闭该活动,但仍然有敬酒的消息(在这种情况下)出现给我的信息。
Problem is once i have hit send i would like to close the activity but still have the toast message (in this case) appear giving me the info.
由于我是新来这个我不知道如何去这一点。我所做的就是等待的信息才能通过,成立了消息,然后关闭该活动。
As i am new to this i am not sure how to go about this. All i have done is wait for the information to come through, set up the message then close the activity.
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();
}
我敢肯定,这是可能以某种方式,甚至可能把它传递给另一个活动。
Im sure this is possible somehow, even to pass it possibly to another activity.
这可能听起来有点迂腐,但它让我学会做事情的新方法......所以,如果任何人都可以在正确的方向指向我,会是巨大的。
It probably sounds a bit pedantic but it allows me to learn new ways of doing things... so if anyone can point me in the right direction that'd be great.
谢谢!
推荐答案
哥们去他们提供妥善解决的 http://mobiforge.com/developing/story/sms-messaging-android u可以从这个链接得到的答案也试试这个<一个href=\"http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/os/SmsMessagingDemo.html\" rel=\"nofollow\">http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/os/SmsMessagingDemo.html
Dude go to this link they have provided proper solution http://mobiforge.com/developing/story/sms-messaging-android u may get answer from this link also try this http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/os/SmsMessagingDemo.html
这篇关于SMSManager和意图之前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!