有没有人知道如果Android设备,手机或平板电脑具有语音功能的程序化检查的好方法? 通过语音功能,我的意思是打电话的能力。我知道有些设备,比如北美的Galaxy标签,没有这种功能。
答案 0 :(得分:3)
我自己没试过,但看起来你需要的细节就在TelephonyManager中:
private boolean hasPhoneAbility()
{
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if(telephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE)
return false;
return true;
}
答案 1 :(得分:1)
我知道很久以前这个问题已经发布了,但我仍然认为我会发布我想出的解决方案,这对我来说是有效的,所以任何有同样问题的人都可以受益。 (因为很多人似乎无法找到解决方案)。
我刚检查了设备的语音信箱号码,显然如果没有设备,那么它不是手机号码。在我的代码中,要检查它,它是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);
}
}
});
答案 2 :(得分:0)
理论上,您应该可以使用Intent.resolveActivity
来执行此操作。特别是Galaxy选项卡存在问题(描述为here)。他们显然报告说他们有召唤能力。您甚至可以成功解决意图。不幸的是,它解决了无操作活动。
答案 3 :(得分:0)
如果没有可用的麦克风,我会认为prepare()会失败:
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) {}