-2

I have schedule to make an android application which used to block spam emails (chosen by myself). However, I cannot find any way to do it. Is it possible to block/reject the email using android programmatically?

In addition, I found that from KitKat version, we will not block a SMS by android programmatically. That means that we can not make an application for blocking the SMS. Is it right?

Thank you in advance

Community
  • 1
  • 1
Jame
  • 3,746
  • 6
  • 52
  • 101

1 Answers1

1

Note:Its just about sms not email.

You can block but in KitKat and greator but there is one condition your app should be default messaging app.

To Check default app

         if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
                final String myPackageName = context.getPackageName();
                if (Telephony.Sms.getDefaultSmsPackage(context).equals(
                        myPackageName)) {
                    flagToCheckForBlock = true;
                    abortBroadcast();
                }
            } else {
                flagToCheckForBlock = true;
                abortBroadcast();
            } 
Sohail Zahid
  • 8,099
  • 2
  • 25
  • 41
  • How about email? A default messaging app means I will receive message in that app, and the sms app of android will not show any mess. is it right? – Jame Jul 27 '16 at 12:10
  • This isn't really correct. The `abortBroadcast()` method is useless in a default app. Not even the default can abort the `SMS_RECEIVED` broadcast, and therefore cannot prevent other apps from receiving messages, if they're listening for them. Also, the default listens for a different broadcast to handle incoming messages, anyway. – Mike M. Jul 27 '16 at 17:17