如何跟踪在Android上的消息? [英] How to track the messages in Android?
问题描述
我想开发一个应用程序,它跟踪发送/接收短信。我的意思是,当用户从设备发送邮件,邮件的细节应保存到由我提供了一份表格。类似地,当设备接收到任何SMS,那么也应该保存到由箱提供一个表
请注意用户采用Android的默认邮件应用程序发送的消息。我的意思是我不是我的整合与默认的消息应用程序。我只需要跟踪该应用程序发送的所有邮件,作为Android的跟踪所有发送的邮件中的已发邮件的文件夹中的信息应用
我将如何做到这一点?请帮我。我不需要答案,但我需要一些线索来做到这一点。
请不建议读取收件箱和发件箱等的消息,因为我想,当用户发送/接收它来保存的消息。不后发送或接收它。
这是容易做到的广播接收机写在你的清单:
编辑:似乎只对工作SMS_RECEIVED看到这个<一href="http://stackoverflow.com/questions/990558/android-broadcast-receiver-for-sent-sms-messages">thread
&LT;接收器安卓名=机器人SMSReceiver。:启用=真正的&GT;
&LT;意图过滤器的Android版本:优先=1000&GT;
&lt;作用机器人:名称=android.provider.Telephony.SMS_RECEIVED/&GT;
&lt;作用机器人:名称=android.provider.Telephony.SMS_SENT/&GT;
&所述; /意图滤光器&gt;
&LT; /接收器&GT;
和权限:
&LT;使用-权限的Android:名称=android.permission.RECEIVE_SMS/&GT;
然后创建接收llike:
公共类SMSReceiver扩展的BroadcastReceiver {
@覆盖
公共无效的onReceive(上下文的背景下,意图意图){
如果(intent.getAction()。等于(android.provider.Telephony.SMS_RECEIVED)){
//做一些与接收到的短信
}否则,如果(intent.getAction()。等于(android.provider.Telephony.SMS_SENT)){
//做一些与sended短信
}
}
}
要处理传入的短信可能会是这样的:
捆绑额外= intent.getExtras();
[对象]的PDU =(对象[])extras.get(的PDU);
对于(对象PDU:PDU)的{
SmsMessage味精= SmsMessage.createFromPdu((byte []的)PDU);
字符串的起源= msg.getOriginatingAddress();
串体= msg.getMessageBody();
....
}
如果你想prevent短信被推在闽台收件箱中,您可以达到此目的:
abortBroadcast();
I want to develop an app which tracks the sent/received SMSs. I mean, when a user sends a message from its device, the message detail should be saved to a table provided by me. Similarly, when the device receives any SMS, then that also should be saved into a table provided by me.
Note that the user uses the default message application of Android to send message. I mean I am not integrating my application with the default message application. I just need to keep track of all messages sent from that application as Android keeps track of all sent messages in Sent Message folder of its Message app.
How would I do this? Please help me. I don't need answers, but I need some clue to do it.
Please don't suggest to read the messages from Inbox and Outbox etc. Because I want to save the messages when user sends/ receives it. Not after sends or receives it.
This is easy to do with a broadcast Receiver write in your Manifest:
edit: seems only to work for SMS_RECEIVED see this thread
<receiver android:name=".SMSReceiver" android:enabled="true">
<intent-filter android:priority="1000">
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
<action android:name="android.provider.Telephony.SMS_SENT"/>
</intent-filter>
</receiver>
And the Permission:
<uses-permission android:name="android.permission.RECEIVE_SMS" />
Then Create the Receiver llike:
public class SMSReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")){
//do something with the received sms
}else if(intent.getAction().equals("android.provider.Telephony.SMS_SENT")){
//do something with the sended sms
}
}
}
To handle a incoming sms might look like:
Bundle extras = intent.getExtras();
Object[] pdus = (Object[]) extras.get("pdus");
for (Object pdu : pdus) {
SmsMessage msg = SmsMessage.createFromPdu((byte[]) pdu);
String origin = msg.getOriginatingAddress();
String body = msg.getMessageBody();
....
}
If you want to prevent a sms to be pushed in the commen InBox, you can achieve this with:
abortBroadcast();
这篇关于如何跟踪在Android上的消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!