0

내가하고 싶은 일은 ContentObserver이 등록 된 Service을 가지고 특정 반응을 수행하기 위해 onChange()을 트리거하는 ContentObserver을 확인하는 것입니다. 나는 단지 /, 또는 OverwriteContentObserver에 그것을 포함 해야하는지 모르겠다, 어느 경우에 내가 정확히 어떻게 해야할지 모르겠다. 모든 도움을 미리 감사드립니다.어떤 ContentObserver가 onChange 메서드를 트리거하는지 확인하는 방법은 무엇입니까?

public class SmsObserverService extends Service { 

private String BABAS = "babas"; 
@Override 
public void onCreate() { 

    Handler handler = new Handler(); 

    this.getContentResolver().registerContentObserver(Uri.parse("content://sms/"), true, new SmsObserver(handler)); 

    //Second observer 
    this.getContentResolver().registerContentObserver(Uri.parse("CallLog.Calls.CONTENT_URI"), true, new SmsObserver(handler)); 

} 


@Override 
public IBinder onBind(Intent intent) { 
    // TODO Put your code here 
    return null; 
} 


public class SmsObserver extends ContentObserver{ 

    public SmsObserver(Handler handler) { 
     super(handler); 


    } 
    @Override 
    public void onChange(boolean selfChange) {   
     super.onChange(selfChange); 

     //Where I should check somehow which ContentObserver triggers the onChange 


     //This code to the sms log stuff, the call log part will be included 
     //when I find out how to check whic observer trigerred the onChange 
     Uri uri = Uri.parse("content://sms/"); 
     Cursor cursor = getApplicationContext().getContentResolver().query(uri, null, null, null, null); 
     cursor.moveToNext(); 


     String body = cursor.getString(cursor.getColumnIndex("body")); 
     String add = cursor.getString(cursor.getColumnIndex("address")); 
     String time = cursor.getString(cursor.getColumnIndex("date")); 


     String protocol = cursor.getString(cursor.getColumnIndex("protocol")); 

     if(protocol == null){ 
      Toast.makeText(getApplicationContext(), "Enviada para: " +add + ", Hora: "+time +" - "+body, Toast.LENGTH_SHORT).show(); 
      Log.i(BABAS, "Enviada para: "+add +" " +"Time: "+time +" - "+body); 
     }else{ 
      Toast.makeText(getApplicationContext(), "Recebida de: "+add + ", Hora: "+time +" - "+body, Toast.LENGTH_SHORT).show(); 
      Log.i(BABAS, "Recebida de: "+add +" " +"Time: "+time +" - "+body); 
     } 

    } 

} 

}

답변

0

단순히 ContentObserver을 확장하고 내가 거기에 실종 무엇이든 추가 할 것입니다.

+0

그게 내가하고 싶은 일이지만, 나는 잘 모릅니다. –

관련 문제