我想用ImageView
拨打电话拨号程序,而我在片段布局中使用Listview
怎么办?
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.activity_appointments, container, false);
ListView listview = (ListView) v.findViewById(R.id.listview);
CustomAdapter customAdapter = new CustomAdapter();
listview.setAdapter(customAdapter);
imgv = (ImageView) v.findViewById(R.id.imphone);
imgv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
makeCall();
}
});
return v;
}
public void makeCall() {
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel" +"99986326"));
startActivity(intent);
}
答案 0 :(得分:1)
您必须像这样更改它
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.fromParts("tel", "+99986326", null));
startActivity(intent);
这不会直接拨打电话,而是打开填充您提供的号码的拨号程序。如果您必须直接从应用程序拨打电话,则必须在清单中包含ACTION_CALL权限,并且还必须在执行上述startactivity代码之前检查权限。