Its actually a lot easier to do for CallLog content provider than it
is for SMS, just use CallLog.Calls.CONTENT_URI for the uri.

        public PhoneTap(Handler handler, String myNumber, Context context){
                super(handler);
                this.myNumber = myNumber;
                this.context = context;
        }

        @Override
        public void onChange(boolean selfChange) {
                if(cur==null){
                        cursorInit(context);
                }

        if (!cur.moveToNext()) {
            //do we really want to close the cursor?
                //cur.close();
            return;
        }

        String number = cur.getString(numberColumn);
        String id = cur.getString(idColumn);
        String type = cur.getString(typeColumn);
        String date = cur.getString(dateColumn);
        String dur = cur.getString(durColumn);
        Date dateN = new Date(Long.parseLong(date));
        Date date2 = new Date();
        Log.i("PHONETAP", date2+": "+dateN+":"+id+", "+number+", "+type
+", "+dur);
        }

        public void cursorInit(Context context){
                String[] projection = new String[]{BaseColumns._ID,
CallLog.Calls.DATE, CallLog.Calls.NUMBER,
                                CallLog.Calls.DURATION, CallLog.Calls.TYPE};
                ContentResolver resolver = context.getContentResolver();
                cur = resolver.query(CallLog.Calls.CONTENT_URI, projection, 
null,
null,
                                "date ASC");

        numberColumn = cur.getColumnIndex(CallLog.Calls.NUMBER);
        typeColumn = cur.getColumnIndex(CallLog.Calls.TYPE);
        dateColumn = cur.getColumnIndex(CallLog.Calls.DATE);
        durColumn = cur.getColumnIndex(CallLog.Calls.DURATION);
        idColumn = cur.getColumnIndex(CallLog.Calls._ID);
        }


On Jun 1, 12:13 am, mike <[email protected]> wrote:
> hi Donal,
>
> this is what i have done for sms
>
>         protected void listeneNativeInbox() {
>                 String url = "content://sms/";
>                 Uri uri = Uri.parse(url);
>
> context.getContentResolver().registerContentObserver(CallLog.Calls.CONTENT_URI,
> true,
>                                 new MyInboxListener(handler));
>
>                 Uri Sms = Uri.parse("content://sms/inbox");
>                 Cursor c = context.getContentResolver().query(Sms, null, 
> null, null,
>                                 null);
>         }
>
>         class MyInboxListener extends ContentObserver {
>
>                 public MyInboxListener(Handler handler) {
>                         super(handler);
>                         // TODO Auto-generated constructor stub
>                 }
>
>                 @Override
>                 public boolean deliverSelfNotifications() {
>                         // TODO Auto-generated method stub
>                         return false;
>                 }
>
>                         public void onChange(boolean selfChange) {
>                         // TODO Auto-generated method stub
>                         Log.v("SMS", "Notification on SMS observer");
>
>                         Message msg = new Message();
>                         msg.obj = "xxxxxxxxxx";
>
>                         handler.sendMessage(msg);
>
>                         Uri uriSMSURI = Uri.parse("content://sms/");
>                         Cursor cur = getContentResolver().query(uriSMSURI, 
> null, null,
>                                         null, null);
>                         cur.moveToNext();
>                         String protocol = 
> cur.getString(cur.getColumnIndex("protocol"));
>                         if (protocol == null) {
>                                 Log.d("SMS", "SMS SEND");
>                                 int threadId = 
> cur.getInt(cur.getColumnIndex("thread_id"));
>                                 Log.d("SMS", "SMS SEND ID = " + threadId);
>                                 getContentResolver().delete(
>                                                 
> Uri.parse("content://sms/conversations/" + threadId),
>                                                 null, null);
>
>                         } else {
>                                 Log.d("SMS", "SMS RECIEVE");
>                                 int threadIdIn = 
> cur.getInt(cur.getColumnIndex("thread_id"));
>                                 getContentResolver().delete(
>                                                 
> Uri.parse("content://sms/conversations/" + threadIdIn),
>                                                 null, null);
>                         }
>                 }
>         }
>
> if i'm going to listen for CallLog changes what are the parameters for
> onChange method??
>
> regards,
> Randika

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

Reply via email to