我想覆盖默认的 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 和发件人号码的邮件。
谢谢, 拉杜
最佳答案
没有您所想的“默认应用程序”。 Android 中应用程序的调度方式是通过 Intents
。应用程序将使用 IntentFilter
来识别它可以处理特定类型的 Intents
。您正在寻找的是一个可以处理 SMSReceived
Intent 的 BroadcastReceiver
。这将使您的应用程序在收到 SMS 时得到通知。为了隐藏通知,您需要使用 SMS ContentProvider
将 SMS 标记为已读。这将从通知托盘中清除通知。除非从 SMS ContentProvider
中删除消息,否则无法从默认消息传递应用程序中隐藏消息。查看this link了解如何开始使用 BroadcastReceivers
。
关于android - 覆盖默认的 android 消息传递应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3752889/