有没有人知道一种良好的编程方式来检查安卓设备(手机或平板电脑)是否具有语音功能?所谓语音功能是指能够打电话的能力。我知道有些设备,比如北美的Galaxy Tab,就没有这个功能。
有没有人知道一种良好的编程方式来检查安卓设备(手机或平板电脑)是否具有语音功能?所谓语音功能是指能够打电话的能力。我知道有些设备,比如北美的Galaxy Tab,就没有这个功能。
虽然我自己没有尝试过,但看起来你需要的详细信息应该在TelephonyManager中:
private boolean hasPhoneAbility()
{
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if(telephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE)
return false;
return true;
}
我知道这个问题很久以前就被发布了,但我仍然想发布我找到的解决方案,目前对我有效,以便任何遇到同样问题的人可以受益。(因为似乎很多人都在寻找解决方案)。
我只是检查设备的语音邮件号码,如果没有,则不是电话。在我的代码中,要检查这个,它是tm.getVoiceMailNumber();
这是我做的:
callButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
String ableToMakePhoneCalls = tm.getVoiceMailNumber(); //check device for voicemail number (null means no voicemail number).
if(ableToMakePhoneCalls == null){ //If the device does not have voicemail, then it must not be a phone. So it can't call.
//I displayed an alert dialog box here
}
else{
String phoneNum = "tel:8885554444";
Intent intentPhone = new Intent(android.content.Intent.ACTION_CALL);
intentPhone.setData(Uri.parse(phoneNum));
startActivity(intentPhone);
}
}
});
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setOutputFile(audio_file);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
try {
mRecorder.prepare();
mRecorder.start();
} catch (Exception e) {}
Intent.resolveActivity
来实现此目的。特别是在Galaxy平板电脑上存在一个问题(在这里描述)。它们显然报告具有呼叫功能。您甚至可以成功解析意图。不幸的是,它解析为无操作活动。