繁体   English   中英

找不到处理 Intent { act=android.intent.action.CALL dat=tel0710000001 } 的活动

[英]No Activity found to handle Intent { act=android.intent.action.CALL dat=tel0710000001 }

当我运行应用程序时出现致命异常错误,

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.CALL dat=tel0710000001 }错误信息

      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();
            }
        }
    }

Android清单

  <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"/>

尝试将此添加到您的 manifest.xml 中:

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

但是,在Reference中,这个权限被归类为“保护级别:危险”,我建议使用这个:

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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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