问题描述
好吧,我创建Android应用程序,我不喜欢让从这里输入数 mostLikelyThingHeard
unfortenately我的code没有出于某种原因
Okay, I am creating an android app, I do like to get the number from an input here mostLikelyThingHeard
unfortenately my code doesn't work for some reason.
例如,当用户说:BEL 0612345678
For example when the user says: bel 0612345678
拨号器必须调用0612345678
The dialer has to call 0612345678
String one = "bel";
if (mostLikelyThingHeard.contains(one)) {
String numbers = mostLikelyThingHeard.replaceAll("[^0-9]", "");
Intent call = new Intent(Intent.ACTION_DIAL);
call.setData(Uri.parse("tel:" + numbers));
tts.speak(numbers + " wordt gebeld.",
TextToSpeech.QUEUE_FLUSH, null);
found = true;
}
我还添加了在AndroidManifest.xml正确的权限,我猜code是错误的。
I also added the right permissions in AndroidManifest.xml, I guess the code is wrong.
推荐答案
您需要从字符串得到的数字是这样的:
You need to get numbers from String like this:
String numbers = mostLikelyThingHeard.replaceAll("[^\\d]", "");
要拨打该号码,就可以使用ACTION_CALL。 ACTION_DIAL将只需打开拨号屏幕,这个数字。此外,你已经初始化的意图,但你缺少调用 startActivity(意向)
To call that number, you can use ACTION_CALL. ACTION_DIAL will just open a dialer screen with that number. Also, you have initialized intent, but you are missing call to startActivity(intent)
Intent call = new Intent(Intent.ACTION_DIAL);
call.setData(Uri.parse("tel:" + numbers));
startActivity(call);
希望这有助于。
这篇关于从输入得到的只是数字并拨打该号码的Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!