在android中从应用程序内调用电话的正确方法
我有一小段代码,基本上应该在按下按钮时拨打电话。我在网上查了一下,所有的来源基本上都给出了相同的代码。但由于某种原因,这段代码不起作用。它使应用程序崩溃,但 LogCat 不显示任何内容(意味着日志完全空白)。我还应该提到,在我的清单文件中,我确实添加了以下权限
<uses-permission android:name = "andriod.permission.CALL_PHONE" />
我的代码如下。任何帮助将不胜感激!
phoneButton.setOnClickListener(new OnClickListener () {
public void onClick(View v) {
try {
final Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:232131232"));
ContactUs.this.startActivity(callIntent);
}catch (ActivityNotFoundException e){
Log.e("Dialing", "call Failed!", e);
}
}
});
I have a small piece of code which is basically supposed to make a phone call when a button is pushed. I looked it up online and all the sources basically gave the same code. But for some reason this code doesn't work. It makes the app crash but the LogCat doesn't display anything (meaning the log is completely blank). I should also mention that in my manifest file I did add the following permission
<uses-permission android:name = "andriod.permission.CALL_PHONE" />
The code I have is as follows. Any help would be greatly appreciated!
phoneButton.setOnClickListener(new OnClickListener () {
public void onClick(View v) {
try {
final Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:232131232"));
ContactUs.this.startActivity(callIntent);
}catch (ActivityNotFoundException e){
Log.e("Dialing", "call Failed!", e);
}
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你第二次把 android 拼写错了...
You spelt android wrong the second time...
听起来您需要添加拨打电话的用户权限。 权限为:
。我相信清单文件中的
Sounds like you need to add the user-permission for making a phone call. I believe the permission is:
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
in your manifest file.
这是我目前正在 HTC Desire 上测试的 Activity 类的片段 -
我建议将
ContactUs.this.startActivity(callIntent);
更改为startActivity(callIntent);
并且再次测试一下。This is a snippet from an Activity class I am currently testing on my HTC Desire -
I suggest changing
ContactUs.this.startActivity(callIntent);
tostartActivity(callIntent);
and testing it again.