Phone Call On TextView Click

后端 未结 1 1256
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-21 03:42

How to make a phone call in android when user Click on textView then automatically dail a number in textView ?

  TextView tv=(TextView) findViewById(R.id.tv_cont         


        
1条回答
  •  无人共我
    2021-01-21 04:09

    Add permission to call in AndroidManifest.xml file.

    
    

    First make your TextView clickable by adding below in your layout.xml

    
    
    

    Then in your Activity Class, inside OnClickListener of that particular TextView add below code

    if (Build.VERSION.SDK_INT > 22) {
    
            if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
    
                ActivityCompat.requestPermissions(MoreProgramDetailActivity.this, new String[]{Manifest.permission.CALL_PHONE}, 101);
    
                return;
            }
            Intent callIntent = new Intent(Intent.ACTION_CALL);
            callIntent.setData(Uri.parse("tel:+" + tv.getText().toString().trim()));
            startActivity(callIntent);
     } else {
    
            Intent callIntent = new Intent(Intent.ACTION_CALL);
            callIntent.setData(Uri.parse("tel:+" + tv.getText().toString().trim()));
            startActivity(callIntent);
     }
    

    0 讨论(0)
提交回复
热议问题