我是这方面的初学者,我正在努力让它发挥作用。
按下按钮时,我只想打开拨号器并自动输入指定的号码。
到目前为止,我已经尝试了以下方法:
Button btn_call_us = (Button) findViewById(R.id.btn_call_us);
btn_call_us.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:00000000"));
startActivity(callIntent);
}
});
我也试过:
Button btn_call_us = (Button) findViewById(R.id.btn_call_us);
btn_call_us.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String phoneno="00000000";
Intent i=new Intent(Intent.ACTION_CALL,Uri.parse(phoneno));
startActivity(i);
}
});
我已将权限 ACTION_CALL 添加到 list 中。
每当我单击“调用”按钮时,应用程序都会强制关闭。
如有任何帮助,我们将不胜感激。
谢谢!
最佳答案
String number = "12345678";
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" +number));
startActivity(intent);
您需要将此权限添加到您的 list 中。
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
关于java - 如何通过 Android 中的按钮调用号码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16412480/