I am working on an android project and I would like to create an application that intercept the inbound calls.How to assign a check box at contact list, in order to be able to select multiple contact persons once?
Here is my code:
//main activity
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
add = (Button)findViewById(R.id.add_reminder);
manage = (Button)findViewById(R.id.manage_reminders);
add.setOnClickListener(this);
manage.setOnClickListener(this);
}
public void onClick(View v) {
switch(v.getId())
{
case R.id.manage_reminders:
break;
case R.id.add_reminder:
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
startActivityForResult(intent, PICK_CONTACT);
break;
}
}
public void onActivityResult(int requestCode, int resultCode, Intent intent)
{
if (requestCode == PICK_CONTACT)
{
Cursor cursor = managedQuery(intent.getData(), null, null, null, null);
cursor.moveToNext();
String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
String name = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME));
Toast.makeText(this, "Contect LIST = "+name, Toast.LENGTH_LONG).show();
}
}//onActivityResult
}
Take a look here: http://www.krvarma.com/2010/08/detecting-incoming-and-outgoing-calls-in-android/
Just make an BroadcastReceiver that listens to:
If the phone state is ‘Ringing’, then there is an incoming call.
Like:
Now the phone number will be printed in logcat.