pra*_*gai 50 android button phone-call
当我在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);
}
});
Run Code Online (Sandbox Code Playgroud)
但是当我跑步并点击按钮时,它会给我错误
ERROR/AndroidRuntime(1021): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.CALL dat=9392438004 }
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
Sha*_*aaz 135
您是否已在清单文件中获得了许可
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
Run Code Online (Sandbox Code Playgroud)
在你的活动里面
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:123456789"));
startActivity(callIntent);
Run Code Online (Sandbox Code Playgroud)
如果您发现任何问题,请告诉我.
Xar*_*mer 14
调用/开始调用有两种意图:ACTION_CALL和ACTION_DIAL.
ACTION_DIAL只会打开dialer with the number填充,但允许用户实际c all or reject the call.ACTION_CALL将立即拨打该号码并需要额外的许可.
所以请确保您拥有该权限
uses-permission android:name="android.permission.CALL_PHONE"
Run Code Online (Sandbox Code Playgroud)
在AndroidManifest.xml中
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dbm.pkg"
android:versionCode="1"
android:versionName="1.0">
<!-- NOTE! Your uses-permission must be outside the "application" tag
but within the "manifest" tag. -->
<uses-permission android:name="android.permission.CALL_PHONE" />
<application
android:icon="@drawable/icon"
android:label="@string/app_name">
<!-- Insert your other stuff here -->
</application>
<uses-sdk android:minSdkVersion="9" />
</manifest>
Run Code Online (Sandbox Code Playgroud)
ken*_*wen 10
上面的所有内容都没有这么做,只需要修改一下这个代码就可以了
Intent i = new Intent(Intent.ACTION_DIAL);
String p = "tel:" + getString(R.string.phone_number);
i.setData(Uri.parse(p));
startActivity(i);
Run Code Online (Sandbox Code Playgroud)
之前检查权限(对于 android 6 及更高版本):
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.CALL_PHONE) ==
PackageManager.PERMISSION_GRANTED)
{
context.startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:09130000000")));
}
Run Code Online (Sandbox Code Playgroud)
小智 5
我也有这样的时间.我没有意识到,除了额外的许可,你需要将"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);
}Run Code Online (Sandbox Code Playgroud)