我必须创建一个
Android应用程序,在手机中显示联系人列表.我成功地设法创建它,但如何在点击(我们选择)上调用特定号码?
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView lView=(ListView)findViewById(R.id.listView1);
ContentResolver resolver=getContentResolver();
Cursor c=resolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null, null, null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);
String[] from=new String[]{ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,ContactsContract.CommonDataKinds.Phone.NUMBER};
int[] to=new int[]{R.id.textView1,R.id.textView2};
SimpleCursorAdapter adapter=new SimpleCursorAdapter(getApplicationContext(), R.layout.indi_view, c, from, to);
lView.setAdapter(adapter);
}
}
最佳答案 您只想像这样使用ACTION_CALL启动意图.
首先从点击发生的项目中获取电话号码.然后使用该代码发起呼叫.
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+phonenumber));
startActivity(callIntent);
希望你能得到答案.