Dialing a phone call on click of textview in android

后端 未结 6 883
醉话见心
醉话见心 2020-12-03 01:05

I have a question that I want to dial a phone call when I click on a text view which also contain a phone number. But when I click on a Text view it returns an error as:

6条回答
  •  情深已故
    2020-12-03 02:05

    Add permission to call in AndroidManifest.xml file.

    
    

    In your textview of your layout.xml file

    
    

    In your activity class. Run-time permission check added.

    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:+" + phoneTV.getText().toString().trim()));
                startActivity(callIntent);
     } else {
    
                Intent callIntent = new Intent(Intent.ACTION_CALL);
                callIntent.setData(Uri.parse("tel:+" + phoneTV.getText().toString().trim()));
                startActivity(callIntent);
     }
    

提交回复
热议问题