android 工作室通话按钮
android studio calling button
我正在尝试制作一个点击按钮,按下时会发出 phone 调用。
这是我的 java:
代码
public void CampusSafClick(View view){
Intent callIntent =new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:6038994210"));
startActivity(callIntent);
}
我知道如何制作 onclick 按钮,所以这不是问题。
清单中有这段代码:
<uses-permission android:name="android.permision.CALL_PHONE"></uses-permission>
我不断收到错误消息很遗憾,您的应用已停止运行。
这是工作代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialContactPhone("123123123");
}
});
}
private void dialContactPhone(final String phoneNumber) {
startActivity(new Intent(Intent.ACTION_DIAL, Uri.fromParts("tel", phoneNumber, null)));
}
我需要在清单上的应用程序列表上方输入代码:
<uses-permission android:name="android.permission.CALL_PHONE"/>
你需要Action_Dial
,
使用下面的代码将打开指定编号的经销商。
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:0123456789"));
startActivity(intent);
需要tel:
前缀,否则会抛出如下异常:java.lang.IllegalStateException: Could not execute method of the activity.
Action_Dial
不需要任何权限。
如果你想直接发起呼叫而不需要用户交互,你可以使用操作Intent.ACTION_CALL
。在这种情况下,您必须在 AndroidManifest.xml
中添加以下权限:
<uses-permission android:name="android.permission.CALL_PHONE" />
使用android进行调用,可以使用Intents来实现。
public void MakePhoneCall(View view){
Intent callIntent =new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:9961907453"));
if (ActivityCompat.checkSelfPermission(MainActivity.this,
Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
return;
}
startActivity(callIntent);
}
清单中有这段代码:
<uses-permission android:name="android.permision.CALL_PHONE"></uses-permission>
如果您使用的 SDK 版本高于 Lolipop,那么您应该包含请求权限。
您可以使用以下代码
intent =new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:+251999999999"));
startActivity(intent);
并包含在清单文件中
<uses-permission android:name="android.permission.CALL_PHONE"/>
ivCall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (serviceListDates.get(position).getUser_mobile().length() != 0) {
final AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext);
alertDialog.setTitle("NKA SERVICE");
alertDialog.setMessage("Do you want to Call ?");
alertDialog.setIcon(R.drawable.call_icon);
alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
((DeliveredServiceOilActivity) mContext).callPhoneNumber
(serviceListDates.get(position).getUser_mobile());
}
});`enter code here
alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
alertDialog.show();
} else
AlertUtils.SHOW_TOAST(mContext, mContext.getString(R.string.please_add_number));
}
});
我正在尝试制作一个点击按钮,按下时会发出 phone 调用。 这是我的 java:
代码public void CampusSafClick(View view){
Intent callIntent =new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:6038994210"));
startActivity(callIntent);
}
我知道如何制作 onclick 按钮,所以这不是问题。
清单中有这段代码:
<uses-permission android:name="android.permision.CALL_PHONE"></uses-permission>
我不断收到错误消息很遗憾,您的应用已停止运行。
这是工作代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialContactPhone("123123123");
}
});
}
private void dialContactPhone(final String phoneNumber) {
startActivity(new Intent(Intent.ACTION_DIAL, Uri.fromParts("tel", phoneNumber, null)));
}
我需要在清单上的应用程序列表上方输入代码:
<uses-permission android:name="android.permission.CALL_PHONE"/>
你需要Action_Dial
,
使用下面的代码将打开指定编号的经销商。
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:0123456789"));
startActivity(intent);
需要tel:
前缀,否则会抛出如下异常:java.lang.IllegalStateException: Could not execute method of the activity.
Action_Dial
不需要任何权限。
如果你想直接发起呼叫而不需要用户交互,你可以使用操作Intent.ACTION_CALL
。在这种情况下,您必须在 AndroidManifest.xml
中添加以下权限:
<uses-permission android:name="android.permission.CALL_PHONE" />
使用android进行调用,可以使用Intents来实现。
public void MakePhoneCall(View view){
Intent callIntent =new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:9961907453"));
if (ActivityCompat.checkSelfPermission(MainActivity.this,
Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
return;
}
startActivity(callIntent);
}
清单中有这段代码:
<uses-permission android:name="android.permision.CALL_PHONE"></uses-permission>
如果您使用的 SDK 版本高于 Lolipop,那么您应该包含请求权限。
您可以使用以下代码
intent =new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:+251999999999"));
startActivity(intent);
并包含在清单文件中
<uses-permission android:name="android.permission.CALL_PHONE"/>
ivCall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (serviceListDates.get(position).getUser_mobile().length() != 0) {
final AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext);
alertDialog.setTitle("NKA SERVICE");
alertDialog.setMessage("Do you want to Call ?");
alertDialog.setIcon(R.drawable.call_icon);
alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
((DeliveredServiceOilActivity) mContext).callPhoneNumber
(serviceListDates.get(position).getUser_mobile());
}
});`enter code here
alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
alertDialog.show();
} else
AlertUtils.SHOW_TOAST(mContext, mContext.getString(R.string.please_add_number));
}
});