Wednesday, 20 February 2013

Sample Sync Adapter description

fetchFriendUpdates()
1) SyncAdapter.onPerformSync()
2) NetworkUtility.fetchFriendUpdates()
-> this method is return the user list, which is store in ur server, and this method is post the username and password and get the user data.
3) ContactManager.syncContacts()
-> this method is syncronize ur raw  contact.
-> call to ContactManager.lookupRawContact(), return the raw contact Id if foundelse retunr 0.
-> Then check the rawcontact id, and decide to contact is add, delete or update.
-> here we go with exiting contact so, go with the update contact.
-> call to ContactManager.updateContact() for updating the exiting contact.
-> in this method (ContactManager.updateContact()) this method is define the Cursor.query for getting the exiting contact.
-> then get the detail of contact and call to method for update of this detail, like ContactOperation.updateName(),ContactOperation.updatePhone,
 ContactOperation.updateEmail, then adding detail which is present but not in the contact.
-> then call to the BatchOperation.add(), for adding the operation, which will perform in future.
-> then call to the BatchOperation.execute() for executing the save operation.


fetchFriendStatuses()
1) SyncAdapter.onPerformSync()
2) NetworkUtility.fetchFriendStatuses()
-> this method is return the user.statuse list, which is store in ur server, and this method is post the username and password and get the user.statuse data.
3) ContactManager.insertStatuses()
-> this method is add the status to contact provider.
-> this method call to the ContactManager.lookupProfile(), this method is return the profileID.
-> then profile_id >0 then adding the statuse by use od StatusUpdates class.
-> then call to the BatchOperation.add(), for adding the operation, which will perform in future.
-> then call to the BatchOperation.execute() for executing the save operation.

Wednesday, 23 January 2013

How To read Contact ID and Name from android


    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
     
        Cursor c=getContacts();
        c.moveToFirst();
   
    while(c.isAfterLast()==false)
    {
    String data="::";
    for(int i=0;i<c.getColumnCount();i++)
    {
    data=data.concat(c.getString(c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME))+":"+c.getString(c.getColumnIndex(ContactsContract.Contacts._ID)));
    }
    Toast.makeText(getApplicationContext(), data,Toast.LENGTH_LONG).show();
    c.moveToNext();
    }
     
    }
 
    private Cursor getContacts()
    {

        Uri uri = ContactsContract.Contacts.CONTENT_URI;
        String[] projection = new String[] {
                ContactsContract.Contacts._ID,
                ContactsContract.Contacts.DISPLAY_NAME,    
        };

        String selection = ContactsContract.Contacts.HAS_PHONE_NUMBER;
        String[] selectionArgs = null;
        String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";

        return managedQuery(uri, projection, selection, selectionArgs, sortOrder);
    }

Tuesday, 22 January 2013

Simple Database Connection with SQLIteDatabase


public void database(View v)
{
//Toast.makeText(getApplicationContext(), "Database", 30).show();
try
{
mdb=openOrCreateDatabase("database", SQLiteDatabase.CREATE_IF_NECESSARY, null);
Toast.makeText(getApplicationContext(), "Database is created", 30).show();
mdb.setLocale(Locale.getDefault());
mdb.setLockingEnabled(true);
mdb.setVersion(1);
}
catch(Exception e)
{
Toast.makeText(getApplicationContext(), e.getMessage().toString(),30).show();
}

}
public void table(View v)
{
try
{
String tab="CREATE TABLE tab(fnm TEXT, lnm TEXT)";
mdb.execSQL(tab);
Toast.makeText(getApplicationContext(), "Table is Created", 30).show();
}
catch(Exception e)
{
Toast.makeText(getApplicationContext(), "Table is already created", 30).show();
}

//Toast.makeText(getApplicationContext(), "Table", 30).show();

}
public void add(View v)
{
ContentValues val=new ContentValues();
val.put("fnm", "abc");
val.put("lnm", "bbc");
long id=mdb.insert("tab", null,val);

Toast.makeText(getApplicationContext(), "Record is inserted"+ id, 30).show();

}

public void update(View v)
{
ContentValues val=new ContentValues();
val.put("fnm", "ccd");
int i=mdb.update("tab", val, "fnm=?", new String[] {"abc"});

Toast.makeText(getApplicationContext(), "Update"+i, 30).show();

}
public void delete(View v)
{
int i=mdb.delete("tab", "fnm=?",new String[] {"ccd"});
Toast.makeText(getApplicationContext(), "Delete"+i, 30).show();
}
public void view(View v)
{
try
{
Cursor c=mdb.query("tab",null,null,null,null,null,null);
c.moveToFirst();

while(c.isAfterLast()==false)
{
String data="::";
for(int i=0;i<c.getColumnCount();i++)
{
data=data.concat(c.getString(i)+"::");
}
Toast.makeText(getApplicationContext(), data,30).show();
c.moveToNext();
}
}
catch(Exception e)
{
Toast.makeText(getApplicationContext(), e.getMessage().toString(), 30).show();
}



}