mercredi 30 décembre 2015

java.lang.IllegalArgumentException: URI: content://com.android.contacts, calling user:

I have created contact change observer, when a user any time change their contact need to know what change they did.

Step 1 :

public class ContactChangeObserver extends ContentObserver {

Context mContext;

public ContactChangeObserver(Handler handler, Context ctx) {
    super(handler);
    mContext = ctx;
}

@Override
public boolean deliverSelfNotifications() {
    return super.deliverSelfNotifications();
}

@Override
public void onChange(boolean selfChange) {
    super.onChange(selfChange);
    Log.e("Content Change", "Added New onChange selfChange");
}

@Override
public void onChange(boolean selfChange, Uri uri) {
    Log.e("NoOf Content Change", "Contant Change Happen");
    super.onChange(selfChange, uri);
    if(mContext != null) {
        Log.e("Content Change Name :", "start checking");
        AppPreferences appPreferences = new AppPreferences(mContext);
        String[] projection = {
                ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
                ContactsContract.CommonDataKinds.Phone.NUMBER
        };

        Cursor cursor = mContext.getContentResolver().query(uri, projection, null, null, null);
        if (cursor.moveToFirst()) {
            String sender = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
            String mobileno = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
            String status = "phone";
            MaraContactsManager.getInstance().updateContactDB(mContext, mobileno, sender, status, appPreferences.getCountryCode());
        }
    }
}

Step 2: have register this by calling at HomeActivity

contactChangeObserver =  new ContactChangeObserver(new Handler(),getApplicationContext());
    getApplicationContext().getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, true, contactChangeObserver);

Step 3: when i change any contact it goes to onChange Methode but I am not getting which contact changes done it says

java.lang.IllegalArgumentException: URI: content://com.android.contacts, calling user: 

Please Help

Aucun commentaire:

Enregistrer un commentaire