Thank you asheesh!!!!

On Wednesday, October 17, 2012 2:34:36 PM UTC+5:30, asheesh arya wrote:
>
> this is the code how to delete the contact,calender and sms using checkbox
>
> --------------------------------------------------------------------------------------------------------------------
> import java.util.Vector;
> import android.app.Activity;
> import android.content.ContentResolver;
> import android.database.Cursor;
> import android.net.Uri;
> import android.os.Bundle;
> import android.provider.Contacts;
> import android.util.Log;
> import android.view.View;
> import android.widget.Button;
> import android.widget.CheckBox;
> import android.widget.Toast;
> public class deleteall extends Activity {
>     String TAG = "Delete Activity";
>     ContentResolver cr = null;
> Activity m_activity = this;
> /** Called when the activity is first created. */
> @Override
> public void onCreate(Bundle savedInstanceState) {
>     super.onCreate(savedInstanceState);
>     setContentView(R.layout.main7);
>     cr = getContentResolver();
>     Button button = null;
>     button = (Button)findViewById(R.id.Button01);//delete button
>     if(button != null){
>             button.setOnClickListener(new View.OnClickListener(){
>
>                             @Override
>                             public void onClick(View v) {
>                                     // TODO Auto-generated method stub
>                                     CheckBox checkbox = null;
>                                     checkbox = 
> (CheckBox)findViewById(R.id.CheckBox01);//contact checkbox
>                                     if(checkbox != null){
>                                             if(checkbox.isChecked()){
>                                                     deleteAllContact();
>                                             }
>                                     }
>                                     checkbox = 
> (CheckBox)findViewById(R.id.CheckBox02);//calendar checkbox
>                                     if(checkbox != null){
>                                             if(checkbox.isChecked()){
>                                                     deleteAllCalendar();
>                                             }
>                                     }
>                                     checkbox = 
> (CheckBox)findViewById(R.id.CheckBox03);//sms checkbox
>                                     if(checkbox != null){
>                                             if(checkbox.isChecked()){
>                                                     deleteAllSms();
>                                             }
>                                     }
>                             }
>             }
>             );
>     }
>     button = (Button)findViewById(R.id.Button02);//exit button
>     if(button != null){
>             button.setOnClickListener(new View.OnClickListener(){
>
>                             @Override
>                             public void onClick(View v) {
>                                     // TODO Auto-generated method stub
>                                     m_activity.finish();
>                             }
>             }
>             );
>     }
>     Log.i(TAG, "Out onCreate()");
> }
>
> void deleteAllContact(){
>     Log.i(TAG, "In deleteAllContact()");
>     Uri uri_contacts = Contacts.People.CONTENT_URI;
>     String[] projection = {Contacts.People._ID};
>     int columnIndex = 0;
>     String str_id = "";
>     Vector<String> vector_id = new Vector<String>();
>     int delRow = 0;
>     String where = "";
>     try {
>             Cursor cursor = cr.query(uri_contacts, projection, null, null, 
> null);
>             if(cursor.moveToFirst()){
>                     do{
>                             columnIndex = 
> cursor.getColumnIndex(Contacts.People._ID);
>                             str_id = cursor.getString(columnIndex);
>                             vector_id.add(str_id);
>                     }while(cursor.moveToNext());
>             }
>             cursor.close();
>             for(int i=0; i<vector_id.size(); i++){
>                     str_id = vector_id.get(i);
>                     where = Contacts.People._ID+"="+str_id;
>                     delRow = cr.delete(uri_contacts, where, null);
>                     Log.i(TAG, "deleteAllContact(),delRow:"+delRow);
>             }
>             } catch (Exception e) {
>                     // TODO Auto-generated catch block
>                     Log.e(TAG, "deleteAllContact(),Exception");
>                     e.printStackTrace();
>             }
>             Log.i(TAG, "Out deleteAllContact()");
>             Toast.makeText(this, "All Contacts from your mobile deleted 
> sucessfully",
>                     Toast.LENGTH_LONG).show();
> }
>
> void deleteAllCalendar(){
>     Log.i(TAG, "In deleteAllCalendar()");
>     String strUriEvents = "content://calendar/events";
>     Uri uri_calendar = Uri.parse(strUriEvents);
>     String str_column_name = "_id";
>     String[] projection = {str_column_name};
>     int columnIndex = 0;
>     String str_id = "";
>     Vector<String> vector_id = new Vector<String>();
>     int delRow = 0;
>     String where = "";
>     try {
>             Cursor cursor = cr.query(uri_calendar, projection, null, null, 
> null);
>             if(cursor.moveToFirst()){
>                     do{
>                             columnIndex = 
> cursor.getColumnIndex(str_column_name);
>                             str_id = cursor.getString(columnIndex);
>                             vector_id.add(str_id);
>                     }while(cursor.moveToNext());
>             }
>             cursor.close();
>             for(int i=0; i<vector_id.size(); i++){
>                     str_id = vector_id.get(i);
>                     where = str_column_name+"="+str_id;
>                     delRow = cr.delete(uri_calendar, where, null);
>                     Log.i(TAG, "deleteAllCalendar(),delRow:"+delRow);
>             }
>             } catch (Exception e) {
>                     // TODO Auto-generated catch block
>                     Log.e(TAG, "deleteAllCalendar(),Exception");
>                     e.printStackTrace();
>             }
>             Log.i(TAG, "Out deleteAllCalendar()");
>             Toast.makeText(this, "All Calender from your mobile deleted 
> sucessfully",
>                     Toast.LENGTH_LONG).show();
> }
>
> void deleteAllSms(){
>     Log.i(TAG, "In deleteAllSms()");
>     Uri uri_sms = Uri.parse("content://sms");;
>     String str_column_name = "_id";
>     String[] projection = {str_column_name};
>     int columnIndex = 0;
>     String str_id = "";
>     Vector<String> vector_id = new Vector<String>();
>     int delRow = 0;
>     String where = "";
>     try {
>             Cursor cursor = cr.query(uri_sms, projection, null, null, 
> null);
>             if(cursor.moveToFirst()){
>                     do{
>                             columnIndex = 
> cursor.getColumnIndex(str_column_name);
>                             str_id = cursor.getString(columnIndex);
>                             vector_id.add(str_id);
>                     }while(cursor.moveToNext());
>             }
>             cursor.close();
>             for(int i=0; i<vector_id.size(); i++){
>                     str_id = vector_id.get(i);
>                     where = str_column_name+"="+str_id;
>                     delRow = cr.delete(uri_sms, where, null);
>                     Log.i(TAG, "deleteAllSms(),delRow:"+delRow);
>             }
>             } catch (Exception e) {
>                     // TODO Auto-generated catch block
>                     Log.e(TAG, "deleteAllSms(),Exception");
>                     e.printStackTrace();
>             }
>             Log.i(TAG, "Out deleteAllSms()");
>             Toast.makeText(this, "All Sms from your mobile deleted 
> sucessfully",
>                     Toast.LENGTH_LONG).show();
> }
> }
> ----------------------------------------------------------------------------xml
>  
> file-----------------------------------------------------------------------
> <?xml version="1.0" encoding="utf-8"?>
> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android";
>     android:orientation="vertical"
>     android:layout_width="fill_parent"
>     android:layout_height="fill_parent"
>     android:background="@drawable/delete"
>     >
> <LinearLayout android:id="@+id/LinearLayout01" 
>     android:layout_width="wrap_content" 
>     android:layout_height="wrap_content" 
>     android:layout_gravity="center">
>     
> <TextView 
>     android:layout_width="fill_parent" 
>     android:layout_height="wrap_content" 
>     android:text="@string/app_name" 
>     android:textSize="20px"/>
> </LinearLayout>
> <LinearLayout 
>     android:id="@+id/LinearLayout02" 
>     android:layout_width="wrap_content" 
>     android:layout_height="wrap_content" 
>     android:orientation="vertical" 
>     android:layout_gravity="center" 
>     android:layout_weight="1">
> <CheckBox android:id="@+id/CheckBox01" 
>     android:layout_width="wrap_content" 
>     android:layout_height="wrap_content" 
>     android:text="Contacts" 
>     android:textSize="20px">
>     
> </CheckBox>
> <CheckBox android:id="@+id/CheckBox02" 
>     android:layout_width="wrap_content" 
>     android:layout_height="wrap_content" 
>     android:text="Calendar" 
>     android:textSize="20px">
>     
> </CheckBox>
> <CheckBox 
>     android:id="@+id/CheckBox03" 
>     android:layout_width="wrap_content" 
>     android:layout_height="wrap_content" 
>     android:text="SMS" 
>     android:textSize="20px">
>     
> </CheckBox>
>
> </LinearLayout>
>
>
>
> <LinearLayout 
>     android:id="@+id/LinearLayout03" 
>     android:layout_height="wrap_content" 
>     android:layout_gravity="center" 
>     android:layout_width="wrap_content">
> <Button android:id="@+id/Button01" 
>     android:layout_height="wrap_content" 
>     android:text="Delete" 
>     android:layout_width="wrap_content" 
>     android:width="100px">
>     
> </Button>
> <Button android:id="@+id/Button02" 
>     android:layout_height="wrap_content" 
>     android:text="Exit" 
>     android:layout_width="wrap_content" 
>     android:width="100px">
>     
> </Button>
> </LinearLayout>
>
>
>
> </LinearLayout>
>
>

-- 
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