我想知道如何在android中打电话给某人?
这是我的代码:
setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(Intent.ACTION_DIAL);
String str = getResources().getString(R.string.emergency_number);
intent.setData(Uri.parse(str));
startActivity(intent);
但它什么都没做? 请帮帮忙?
答案 0 :(得分:1)
要在您的应用中使用拨号器应用,您必须做两件事。
<uses-permission android:name="android.permission.CALL_PHONE" />
setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
String str = getResources().getString(R.string.emergency_number);
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + str ));
startActivity(callIntent);
}
});
答案 1 :(得分:0)
btn_dailer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final int request_code = 1;
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+mobile_no.trim()));
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.M)
{
if(ContextCompat.checkSelfPermission(library_incharge.this,Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED)
{
ActivityCompat.requestPermissions(library_incharge.this,new String[]{Manifest.permission.CALL_PHONE},request_code);
}
else
{
startActivity(callIntent);
}
}
}
});