gpt4 book ai didi

java - 打开联系人后如何直接调用电话

转载 作者:行者123 更新时间:2023-12-02 04:30:01 26 4
gpt4 key购买 nike

当我点击按钮选择联系人并选择联系人时不调用该号码时的问题,我想在选择号码时直接调用电话

buttoncontact = findViewById(R.id.choosecontact);


public void choosecontact1 (View view){

Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);

intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
startActivityForResult(intent, PICK_CONTACT)


}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
String call = buttoncontact.getText().toString();


if ((requestCode == 1) && (resultCode == RESULT_OK)) {
Cursor cursor = null;
try {
Uri uri = data.getData();
cursor = getContentResolver().query(uri, new String[] { ContactsContract.CommonDataKinds.Phone.NUMBER }, null, null, null);
if (cursor != null && cursor.moveToNext()) {
String phone = cursor.getString(0);

//该代码的问题

                Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse(String.valueOf("tel:" + CONTENT_TYPE)));

//我想打开电话联系人并直接调用

                if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.


return;

}

startActivity(intent);

}
} catch (Exception e) {
e.printStackTrace();
}
}
}

最佳答案

什么是“CONTENT_TYPE”?不应该是你刚刚得到的电话字符串吗?

intent.setData(Uri.parse("tel:" + phone));

关于java - 打开联系人后如何直接调用电话,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56592220/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com