Override default android messaging app

I want to override the default messaging app for Android. If I receive sms or mms, I want to send it by e-mail, but I do not want to receive notifications by phone. So basically I want to replace the default messaging application.

How can I make my application default to those who accept sms?


Many thanks. This is exactly what I need. But I have one more problem. I used the receiver to receive the message ... but I don’t know how to find the message on 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---
            ...

    }

Is there a way to identify a message as an identifier? Now I find a message comparing the bofy and sender numbers for all messages in the inbox.

Thanks Radu

+3
3

, , . Android Intents. IntentFilter , Intents. BroadcastReceiver, SMSReceived. SMS-. , SMS SMS ContentProvider. . , SMS ContentProvider. , BroadcastReceivers.

+8

. BroadcastReceiver ( 100) abortBroadcast, , BroadcastReceivers. , , -, . , SMS_SENT , , MMS_SENT .

0

If you send the priority of your BroadcastReceiver high enough, your application will be the first to receive the message before the message is saved to the database. I guess the solution would be to store the message in the database on my own and call it abortBroadcast();, but I have not tried it myself yet.

Good luck

0
source

Source: https://habr.com/ru/post/1765651/


All Articles