简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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