覆盖默认的Andr​​oid消息应用程序 [英] Override default android messaging application

查看:119
本文介绍了覆盖默认的Andr​​oid消息应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要覆盖默认的Andr​​oid消息应用程序。 如果我收到一个短信或彩信我想发送到电子邮件,但我不希望在手机的任何通知。 所以基本上我想要替换默认的消息传递应用程序。

I want to override the default android messaging application. If I receive a sms or mms I want to send that to email but i don't want any notification on phone. So basically I want to replace the default messaging application.

我怎样才能让我的应用程序的默认一个收到短信?

How can I make my application the default one that receive the sms?

非常感谢。这正是我需要的。但我有一个问题。 我使用的接收器得到的消息......但我不知道如何找到邮件中的电话,并将其标记为已读。

Thanks a lot. That is exactly what I need. But I have one more problem. I used the receiver to get the message ... but I don't know how to find the message in the phone and mark it as read.

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和发件人号码在收件箱中的所有邮件的邮件。

Is there any way in which I can identify the message like an id? Now I find the message comparing the bofy and sender number for all messages in inbox.

谢谢, 拉杜

推荐答案

有没有你想的办法是默认应用程序。应用程序的调度是Android上的方法是通过意图。应用程序西港岛线使用的IntentFilter 来确定它可以处理特定类型的意图的。您正在寻找的是一个的BroadcastReceiver ,可以处理 SMSReceived 意图。这将允许在收到短信时将通知您的应用程序。为了隐藏的通知,您将需要标记短信为已读使用SMS 的ContentProvider 。这将清除通知了通知托盘。有没有办法隐藏从默认的消息应用程序的消息,除非您从SMS 的ContentProvider 删除信息。请查看如何开始使用 BroadcastReceivers此链接

There isn't a "default application" in the way you're thinking. The way applications are dispatched in Android is through Intents. An application wil use an IntentFilter to identify that it can handle specific types of Intents. What you're looking for is a BroadcastReceiver that can handle the SMSReceived intent. That will allow your application to be notified when an SMS is received. In order to hide the notification, you will need to mark the SMS as read using the SMS ContentProvider. That will clear the notification out of the notification tray. There is no way to hide a message from the default messaging application unless you delete the message from the SMS ContentProvider. Check out this link for how to get started with BroadcastReceivers.

这篇关于覆盖默认的Andr​​oid消息应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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