简体   繁体   English

在片段中使用listview并拨打拨号程序

[英]Using listview in fragments and making a call to dialer

I want to call phone dialer by an ImageView and I am using Listview in a fragment layout what should I do? 我想通过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);
    }

You have to change it like this 你必须这样改变

Intent intent = new Intent(Intent.ACTION_DIAL, Uri.fromParts("tel", "+99986326", null));
startActivity(intent);

This will not make call directly but open the dialer populating the number you provided. 这不会直接拨打电话,而是打开填充您提供的号码的拨号程序。 If you have to make call directly from app, then ACTION_CALL permission must be included in manifest and also it is necessary to check for permission before executing the startactivity code above. 如果您必须直接从应用程序拨打电话,那么ACTION_CALL权限必须包含在清单中,并且在执行上述startactivity代码之前必须检查权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM