Thank you, man.
Well, I would try it again, please help me out.
My question is, if you want to block a message based on the sender's number,
probably you would code like this as I did,
cursor = context.getContentResolver().query(...., malicious_number, ...);
Uri mUri = Uri.parse("content://sms/" + cursor.getString(0));
context.getContentResolver().delete(mUri, null, null);
Those code works sometimes on the HTC Hero + Android 2.1, preventing the new
message showing in the Message app, but sometimes just doesn't. Even if it
works, the new message still trigger a notification and a ring sound. That
is not what we call blocking, isn't it?
So, is there any to target and block a message *silently*?
Thank you.

On 30 July 2010 15:05, Zsolt Vasvari <zvasv...@gmail.com> wrote:

> If you asked a specific question, you *may* get an answer (maybe 10%
> of the time), but basically asking to fix your app will not get an
> answer for certain.
>
> On Jul 29, 6:22 pm, Leonardo <stone198...@gmail.com> wrote:
> > Hi, guys,
> > I made a app to block some junk messages. That app would delete the
> messages
> > from the senders specified in the ban list. That app works in a way, but
> has
> > some defects, as follows,
> > 1. Sometime it just doesn't work, missing the new message to delete.
> > 2. Even if it works deleting the message, a notification sound and
> message
> > still occur.
> > Therefore, could any improvement be made to 100% block messages without
> any
> > notifications?
> > Please check the codes below, and see what I can do.
> > Thank you.
> >
> >
> ===========================================================================­=============
> >
> > import android.app.Activity;
> > import android.content.BroadcastReceiver;
> > import android.content.Context;
> > import android.content.ContextWrapper;
> > import android.content.Intent;
> > import android.content.SharedPreferences;
> > import android.database.Cursor;
> > import android.net.Uri;
> > import android.os.Bundle;
> > import android.telephony.SmsMessage;
> > import android.util.Log;
> > import android.widget.Toast;
> >
> > public class MySMSReceiver extends BroadcastReceiver
> > {
> >   private static final String mACTION =
> > "android.provider.Telephony.SMS_RECEIVED";
> >   private String str_numbers, current_number;
> >   private int killed;
> >   public static final String PREFS_NAME = "LEONARDO_JUNKILLER_PREFS";
> >   private String[] numbers;
> >   Cursor cursor;
> >
> >   @Override
> >   public void onReceive(Context context, Intent intent)
> >   {
> >     //get the banned numbers list from application's preference
> >     SharedPreferences settings = context.getSharedPreferences(PREFS_NAME,
> > 0);
> >     str_numbers = settings.getString("NUMBERS", null);
> >     killed = settings.getInt("KILLED", 0);
> >     if (str_numbers == null)
> >     {
> >       return;
> >     } else
> >     {
> >       numbers = str_numbers.split("\\s+");
> >       for(String number:numbers)
> >       {
> >         number.trim();
> >       }
> >     }
> >
> >     //check if it is a message
> >     if (intent.getAction().equals(mACTION))
> >     {
> >       // get the content from the intent
> >       Bundle bundle = intent.getExtras();
> >       if (bundle != null)
> >       {
> >         Object[] myOBJpdus = (Object[]) bundle.get("pdus");
> >         SmsMessage[] messages = new SmsMessage[myOBJpdus.length];
> >         for (int i = 0; i < myOBJpdus.length; i++)
> >         {
> >           messages[i] = SmsMessage.createFromPdu((byte[]) myOBJpdus[i]);
> >         }
> >         //for each message in the intent, check if it is a junk message
> and
> > delete it if so.
> >         for (SmsMessage currentMessage : messages)
> >         {
> >           // get the sender's number for that message
> >           current_number = currentMessage.getDisplayOriginatingAddress();
> >           // if the number is in the ban list, then find and delete all
> of
> > the received messages belonging to that number, including the new one and
> > existing ones.
> >           if (toKill(current_number))
> >           {
> >             cursor = context.getContentResolver().query(
> >                 Uri.parse("content://sms/"),
> >                 new String[]{"_id", "thread_id", "address"},
> >                 "address=\"" + current_number + "\"",
> >                 //"address=" + current_number,
> >                 null,
> >                 null);
> >
> >             if (cursor.moveToFirst())
> >             {
> >               do
> >               {
> >                 Log.i("JUNKILLER", "The message id:" +
> cursor.getString(0) +
> > ";address:" + cursor.getString(2) + " is deleted");
> >                 Uri mUri = Uri.parse("content://sms/" +
> > cursor.getString(0));
> >                 context.getContentResolver().delete(mUri, null, null);
> >                 killed++;//count the deleted messages for a banned
> number.
> >               } while (cursor.moveToNext());
> >             }
> >             cursor.close();
> >           }
> >         }
> >       }
> >     }
> >     SharedPreferences.Editor editor = settings.edit();
> >     editor.putInt("KILLED", killed);
> >     editor.commit();
> >   }
> >
> >   private boolean toKill(String number_check)
> >   {
> >     for (String number : numbers)
> >     {
> >       if (number_check.indexOf(number) >= 0)
> >       {
> >         return true;
> >       }
> >     }
> >     return false;
> >   }
> >
> >
> >
> > }- Hide quoted text -
> >
> > - Show quoted text -
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to