我想覆盖默认的 android 消息传递应用程序。如果我收到短信或彩信,我想将其发送到电子邮件,但我不想在电话上收到任何通知。所以基本上我想替换默认的消息传递应用程序。
如何使我的应用程序成为接收短信的默认应用程序?
非常感谢。这正是我所需要的。但我还有一个问题。我使用接收器获取消息......但我不知道如何在手机中找到消息并将其标记为已读。
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
//---get the SMS message passed in---
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String str = "";
if (bundle != null)
{
//---retrieve the SMS message received---
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for (int i=0; i<msgs.length; i++){
msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
str += "SMS from " + msgs[i].getOriginatingAddress();
str += " :";
str += msgs[i].getMessageBody().toString();
str += "\n";
}
//---display the new SMS message---
Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
//---find and mark the messages as read---
Uri uriSms = Uri.parse("content://sms/inbox/");
try{
Cursor c = context.getContentResolver().query(uriSms, null,null,null,null);
//---code to find the message by body and sender---
...
}
有什么方法可以像 id 一样识别消息?现在,我找到了比较收件箱中所有邮件的 bofy 和发件人编号的邮件。
谢谢,拉杜