How to check if an Android device has voice capabilities

后端 未结 4 2028
孤街浪徒
孤街浪徒 2021-02-06 15:11

Does anyone know a good way of programmaticaly checking if an Android device, phone or tablet, has voice capabilities? By voice capabilities I mean capability to make phone call

4条回答
  •  半阙折子戏
    2021-02-06 16:03

    I know this question was posted a long time ago, but I still thought I would post the solution I came up with that works for me so far, just so anyone with the same problem can benefit. (Because it seems like lots of people are having trouble finding a solution).

    I just checked for the device's voicemail number, and obviously if it doesn't have one, then it is not a phone. In my code, to check this, it is tm.getVoiceMailNumber();

    Here's what I did:

    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);
                }
            }
        });
    

提交回复
热议问题