簡體   English   中英

在片段中使用listview並撥打撥號程序

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM