SMS Receiver for AND API 19 and higher

时光毁灭记忆、已成空白 提交于 2019-12-12 01:05:35

问题


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

|improve this question

来源:https://stackoverflow.com/questions/38242749/sms-receiver-for-and-api-19-and-higher

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!