1

My job is to create SMS APP to hide selected numbers so that from falling further into default SMS app, this task is simple API for AND <19 using this code.

public class SMSReceiver extends BroadcastReceiver {
public static String TAG = "SMSReceiver";
ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_MUSIC, 100);

public SMSReceiver() {
}

@Override
public void onReceive(Context context, Intent intent) {
    SMS_Throttle.VytvorDatabazi(context);
    String act = intent.getAction();
    Log.d(TAG, act);
    if (Dtb.HodnotaZNastaveniINT(ENastaveni.START_SKRYTE_SLUZBY, 1) == 1) {
        Bundle bundle = intent.getExtras();
        SmsMessage[] msgs = null;
        boolean isAbort = false;
        if (bundle != null) {
            Object[] pdus = (Object[]) bundle.get("pdus");
            msgs = new SmsMessage[pdus.length];
            String lst[][] = SMS_Throttle.getTlfCisla(context);
            String[] l = new String[lst.length];
            for (int j = 0; j < lst.length; j++)
                l[j] = lst[j][0];
            for (int i = 0; i < msgs.length; i++) {
                msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
                for (int j = 0; j < l.length; j++) {
                    if (msgs[i].getOriginatingAddress().endsWith(l[j])) {
                        if (Dtb.HodnotaZNastaveniINT(ENastaveni.PRISLA_AKTIVITA, 0) == 1) {
                            tg.startTone(ToneGenerator.TONE_DTMF_5, 30);
                            Toast.makeText(context, msgs[i].getMessageBody(), Toast.LENGTH_LONG).show();
                        }
                        isAbort = true;
                        Dtb.UlozActivitu(l[j], msgs[i].getMessageBody(), EKomunType.RECEIVE_SMS);
                    }
                }
            }
        }
        if (isAbort) {
            abortBroadcast();
        }
    }
}

}

Important:

Earlier versions of the API perfect shot abortBroadcast (). Thus, if the sender's number is listed in my list see the condition if (msg [i] .getOriginatingAddress (). EndsWith (l [i])) {then the SMS will be saved in my database and do not fall into default app for text messaging.

If the number is not listed in my list, then into my database to store MUST but you must fall into default messaging app.

Problem arose in API> = 19 where the abortbroadcast not work at all and moreover were removed right at the possibility of deletion of selected SMS from default SMS app.

Advise someone how to solve the problem when you need to use my SMS receiver while the default? I've already read through almost everything http://android-developers.blogspot.cz/2013/10/getting-your-sms-apps-ready-for-kitkat.html but also many posts on stackoverflow but I never thought to address this encountered.

Thanks for every idea

VladislavK
  • 39
  • 1
  • 2
  • "Advise someone how to solve the problem when you need to use my SMS receiver while the default?" - This is unclear. Do you mean your app _is_ the default, or is _not_ the default? – Mike M. Jul 07 '16 at 10:20
  • OK, since you don't want to respond, for some reason: If your app is _not_ the default, you cannot stop the default app from receiving and writing incoming messages. If your app _is_ the default, then you just need to not write whichever incoming messages you don't want to, but you can't stop any other app from getting the `SMS_RECEIVED` broadcast, if they're listening for it. – Mike M. Jul 07 '16 at 12:05
  • OK, better explain the problem. I have two kinds of SMS The first is a normal human communication and this communication I need to capture the default SMS app. The second is SMS communications from the sender that monitors the production machine. This report is full of meaningless numbers describing the state of the facilities. I this message, I need another receiver to intercept After dismantling the report could in my application to declare alarm, draw a graph, etc. – VladislavK Jul 07 '16 at 12:27
  • A report on these facilities should appear in the default SMS app. One reason why not show is the one that these reports will come about as 10 times per minute - a lot of them. A problem is that this ceased to function after it has been necessary to buy new phones to employees with ANDROID API version> = 19 It's clear? – VladislavK Jul 07 '16 at 12:28
  • Yes, and my previous comment still applies. If your app is not the default SMS app, it cannot stop the default app from receiving and saving its incoming messages. If you want to keep using SMS for this functionality, I see two options: 1.) Make your app the default SMS app. The default is responsible for saving messages and creating Notifications, and it can choose not to do those things for your report messages. 2.) Switch to using data SMS for the reports. These are addressed to specific apps/ports, and the default app should not react to them at all. – Mike M. Jul 07 '16 at 12:46
  • Sorry mistake. A reports that the facilities may not appear in the default SMS app. – VladislavK Jul 07 '16 at 12:50
  • Yeah, I figured that's what you meant. – Mike M. Jul 07 '16 at 12:52

0 Answers0