-1
我写了一个使用语音识别并将语音保存为字符串的Android应用程序。现在,我可以访问此字符串的不同部分,例如,当我说拨打父亲时,我需要检索父亲的号码联系人。在android中拨打联系人
private void call() {
Intent in=new Intent(Intent.ACTION_CALL,Uri.parse("0000000000"));
try{
startActivity(in);
}
catch (android.content.ActivityNotFoundException ex){
Toast.makeText(getApplicationContext(),"yourActivity is not founded",Toast.LENGTH_SHORT).show();
}
}
我知道这个功能,但不是给Uri.parse的实际数量,我需要通过爸爸的号码it.For例如像Uri.parse(dad.PhoneNumber)。如何我可以通过使用名称从联系人中检索电话号码吗?谢谢。
谢谢,但我得到这个错误:java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.shahin.test/com.example.shahin.test.call}:android.database.CursorIndexOutOfBoundsException:Index - 1请求,大小为1 – shahin
尝试检查游标是否返回有效值。创建游标后,只需添加: if(cursor!= null)if(cursor.moveToFirst()){0}首先发现所需字段的索引(Number) final int indexNumber = cursor.getColumnIndex ContactsContract.CommonDataKinds.Phone.NUMBER); String number = cursor.getString(indexNumber); } } 如果该值不存在,则光标将为空,并可能发生此错误。 – oleonardomachado