Home > Software design >  No Activity found to handle Intent { act=android.intent.action.CALL dat=tel0710000001 }
No Activity found to handle Intent { act=android.intent.action.CALL dat=tel0710000001 }

Time:04-12

When I run the app there is an Fatal exception error,

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.CALL dat=tel0710000001 } Error message

      private static final int REQUEST_CALL = 1;
      private TextView callText;
      private AppCompatButton callTo;


         callTo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                    CallButton();[enter image description here][1]
            }
        });
        
    }

    private void CallButton() {
            String number =  callText.getText().toString();
            if (number.trim().length()>0){
                if(ContextCompat.checkSelfPermission(MyProfileActivity.this, Manifest.permission.CALL_PHONE )!= PackageManager.PERMISSION_GRANTED){
                    ActivityCompat.requestPermissions(MyProfileActivity.this,new String[]{Manifest.permission.CALL_PHONE},REQUEST_CALL);
                }
                else {
                    String dial = "tel"   number;
                    startActivity(new Intent(Intent.ACTION_CALL, Uri.parse(dial)));
                }
            }
        }

@Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (requestCode == REQUEST_CALL) {
            if (grantResults.length > 0) {
                if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    CallButton();
                }
            } else {
                Toast.makeText(this, "Permission Denied", Toast.LENGTH_SHORT).show();
            }
        }
    }

AndroidManifest

  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.CALL_PHONE"/>

CodePudding user response:

try add this in your manifest.xml :

<uses-permission android:name="android.permission.CALL_PHONE" />

But, in the Reference, this permission is classified who "Protection level: dangerous", I recommend use this:

Kotlin:

  val i = Intent(Intent.ACTION_DIAL)
  i.data = Uri.parse("tel:$phone")
  startActivity(i)

Java:

 Intent i =new Intent(Intent.ACTION_CALL);
 i.setData(Uri("tel:" phone));
 startActivity(i);
  • Related