失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > android点击号码打电话 android-拨打电话单击一个按钮

android点击号码打电话 android-拨打电话单击一个按钮

时间:2020-04-14 00:03:26

相关推荐

android点击号码打电话 android-拨打电话单击一个按钮

android-拨打电话单击一个按钮

我在按android中的按钮时正尝试拨打电话

((Button)findViewById(R.id.button1)).setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

String phno="10digits";

Intent i=new Intent(Intent.ACTION_DIAL,Uri.parse(phno));

startActivity(i);

}

});

但是当我运行并单击按钮时,它给了我错误

ERROR/AndroidRuntime(1021): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.CALL dat=9392438004 }

我该如何解决这个问题?

13个解决方案

135 votes

您是否已在清单文件中授予权限

在你的活动中

Intent callIntent = new Intent(Intent.ACTION_CALL);

callIntent.setData(Uri.parse("tel:123456789"));

startActivity(callIntent);

如果您有任何问题,请告诉我。

Shaista Naaz answered -01-26T04:24:43Z

14 votes

调用/开始调用有两种意图:ACTION_CALL和ACTION_DIAL。

ACTION_DIAL仅会打开填写的dialer with the number,但允许用户实际打开all or reject the call。 ACTION_CALL将立即拨打电话,并且需要额外的许可。

因此,请确保您拥有许可

uses-permission android:name="android.permission.CALL_PHONE"

在您的AndroidManifest.xml中

xmlns:android="/apk/res/android"

package="com.dbm.pkg"

android:versionCode="1"

android:versionName="1.0">

android:icon="@drawable/icon"

android:label="@string/app_name">

Xar E Ahmer answered -01-26T04:25:16Z

12 votes

将您的字符串更改为String phno="tel:10digits";,然后重试。

Harshad answered -01-26T04:25:36Z

10 votes

以上都不起作用,因此需要修改一下对我有用的代码

Intent i = new Intent(Intent.ACTION_DIAL);

String p = "tel:" + getString(R.string.phone_number);

i.setData(Uri.parse(p));

startActivity(i);

kenwen answered -01-26T04:25:56Z

5 votes

我也为此感到难过。 我没有意识到,除了额外的权限外,您还需要在包含数字的字符串后附加“ tel:”。 这是我的功能正常后的样子。 希望这可以帮助。

@Override

public void onClick(View v) {

Intent intent = new Intent(Intent.ACTION_DIAL);

String temp = "tel:" + phone;

intent.setData(Uri.parse(temp));

startActivity(intent);

}

JCrooks answered -01-26T04:26:21Z

4 votes

添加“ tel:”以及您要拨打的电话号码,然后开始您的活动。

Intent myIntent = new Intent(Intent.ACTION_CALL);

String phNum = "tel:" + "1234567890";

myIntent.setData(Uri.parse(phNum));

startActivity( myIntent ) ;

Ashu Singh answered -01-26T04:26:41Z

4 votes

要将代码放在一行内,请尝试以下操作:

startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:123456789")));

以及适当的清单许可:

希望这可以帮助!

Brian answered -01-26T04:27:09Z

3 votes

之前检查权限(对于android 6及更高版本):

if (ActivityCompat.checkSelfPermission(context, Manifest.permission.CALL_PHONE) ==

PackageManager.PERMISSION_GRANTED)

{

context.startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:09130000000")));

}

javadaskari answered -01-26T04:27:29Z

2 votes

对于使用AppCompat的用户...请尝试此

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.content.Intent;

import android.util.Log;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.Toast;

import .Uri;

public class MainActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

Button startBtn = (Button) findViewById(R.id.db);

startBtn.setOnClickListener(new View.OnClickListener() {

public void onClick(View view) {

makeCall();

}

});

}

protected void makeCall() {

EditText num = (EditText)findViewById(R.id.Dail);

String phone = num.getText().toString();

String d = "tel:" + phone ;

Log.i("Make call", "");

Intent phoneIntent = new Intent(Intent.ACTION_CALL);

phoneIntent.setData(Uri.parse(d));

try {

startActivity(phoneIntent);

finish();

Log.i("Finished making a call", "");

} catch (android.content.ActivityNotFoundException ex) {

Toast.makeText(this, "Call faild, please try again later.", Toast.LENGTH_SHORT).show();

}

}

}

然后将此添加到您的清单中,

X-Black... answered -01-26T04:27:53Z

1 votes

设备上支持电话也是很好检查

private boolean isTelephonyEnabled(){

TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);

return tm != null && tm.getSimState()==TelephonyManager.SIM_STATE_READY

}

Aristo Michael answered -01-26T04:28:13Z

1 votes

I hope, this short code is useful for You,

## Java Code ##

startActivity(new Intent(Intent.ACTION_DIAL,Uri.parse("tel:"+txtPhn.getText().toString())));

----------------------------------------------------------------------

Please check Manifest File,(for Uses permission)

## Manifest.xml ##

xmlns:android="/apk/res/android"

package="com.dbm.pkg"

android:versionCode="1"

android:versionName="1.0">

## uses-permission for Making Call ##

android:icon="@drawable/icon"

android:label="@string/app_name">

RajeshkumarG answered -01-26T04:28:28Z

0 votes

我刚刚在Android 4.0.2设备(GN)上解决了该问题,并且适用于该设备/版本的唯一版本类似于具有CALL_PHONE权限并回答的第一个5星标:

Intent callIntent = new Intent(Intent.ACTION_CALL);

callIntent.setData(Uri.parse("tel:123456789"));

startActivity(callIntent);

使用任何其他解决方案,我在此设备/版本上都收到了ActivityNotFoundException。较旧的版本呢? 有人会提供反馈吗?

BossOss answered -01-26T04:28:53Z

0 votes

经许可:

Intent callIntent = new Intent(Intent.ACTION_CALL);

callIntent.setData(Uri.parse("tel:9875432100"));

if (ActivityCompat.checkSelfPermission(yourActivity.this,android.Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {

if (ActivityCompat.shouldShowRequestPermissionRationale(yourActivity.this,

android.Manifest.permission.CALL_PHONE)) {

} else {

ActivityCompat.requestPermissions(yourActivity.this,

new String[]{android.Manifest.permission.CALL_PHONE},

MY_PERMISSIONS_REQUEST_CALL_PHONE);

}

}

startActivity(callIntent);

Santhosh answered -01-26T04:29:13Z

如果觉得《android点击号码打电话 android-拨打电话单击一个按钮》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。