我目前正在开发一个 Android 应用程序,需要一个启动电话的功能,所以我添加了这段代码。
public void dialPhoneNumber(String phoneNumber) {
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:" + phoneNumber));
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
Run Code Online (Sandbox Code Playgroud)
..它似乎在旧的 Android 版本中完美工作,但是当我在 Android 11 中测试它时,它根本不起作用我尝试action_call并添加了权限<uses-permission android:name="android.permission.CALL_PHONE" />仍然不起作用。