[英]Using listview in fragments and making a call to dialer
我想通过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);
}
你必须这样改变
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.fromParts("tel", "+99986326", null));
startActivity(intent);
这不会直接拨打电话,而是打开填充您提供的号码的拨号程序。 如果您必须直接从应用程序拨打电话,那么ACTION_CALL权限必须包含在清单中,并且在执行上述startactivity代码之前必须检查权限。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.