建立在Android的短信应用程序? [英] Creating a SMS Application in Android?

查看:126
本文介绍了建立在Android的短信应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建短信应用程序发送和接收短信。

I am creating an SMS Application to send and receive SMS.

我可以用下面的code发送短信:

I am able to send SMS using the following code:

SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null,message , pi, null); 

我希望收到短信,并把它们放在我自己的收件箱。如何创建这样的收件箱?我想它以同样的方式作为一个正常的收件箱。

I would like to receive SMS and put them in my own inbox. How do I create this inbox? I would like it to work the same way as a normal inbox.

Bundle bundle = intent.getExtras();     
Object[] pdus = (Object[]) bundle.get("pdus"); 
SmsMessage[] messages = new SmsMessage[pdus.length];    
for (int i = 0; i < messages.length; i++) {

    messages[i] = SmsMessage.createFromPdu((byte[])pdus[i]); 
    Log.v("SMSFun","Body: " + messages[i].getDisplayMessageBody());
    Log.v("SMSFun","Address: " + messages[i].getDisplayOriginatingAddress());   
    //If say we wanted to do something based on who sent it       
    if (messages[i].getDisplayOriginatingAddress().contains("5556")) {

        // we could launch an activity and pass the data   
        Intent newintent = new Intent(ctx, SecretMessage.class);    
        newintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        newintent.putExtra("address", messages[i].getDisplayOriginatingAddress());
        newintent.putExtra("message", messages[i].getDisplayMessageBody());
        ctx.startActivity(newintent);
    }
}

我如何保存收到的短信收件箱?

How do I store incoming SMS in the inbox?

是否有可能在Android的收听特定的端口号的短信?

Is it possible in Android to listen to particular port number for SMS?

推荐答案

我不认为你可以将短信在不同的收件箱和你不听一个端口,你用它来获得手机短信 BroadcastReceiver的

I don't think you can place sms in different inboxes and you don't listen to a port to get SMS you use a BroadcastReceiver.

我会建议你去通过开放源代码 smspopup 应用以获得一个更好地了解如何的东西一般工作的短信。

I would recommend you to go through the open source smspopup app to get a better idea of how things work for sms in general.

这篇关于建立在Android的短信应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆