我正在开发一个Android项目,我想创建一个拦截入站呼叫的应用程序。如何在联系人列表中分配一个复选框,以便能够选择多个联系人一次?
这是我的代码:
//主要活动
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
}
答案 0 :(得分:0)
看看这里:http://www.krvarma.com/2010/08/detecting-incoming-and-outgoing-calls-in-android/
只需制作一个侦听的BroadcastReceiver:
android.intent.action.PHONE_STATE
如果手机状态为“振铃”,则有来电。
TelephonyManager.EXTRA_STATE
像:
public class IncomingCallReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
if(null == bundle)
return;
String state = bundle.getString(TelephonyManager.EXTRA_STATE);
if(state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_RINGING))
{
String phonenumber = bundle.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
Log.i("IncomingCallReceiver","Incoming Number: " + phonenumber);
}
}
}
现在电话号码将以logcat打印。