How to detect if device is capable of calling and messaging

后端 未结 6 1381
滥情空心
滥情空心 2020-12-20 12:03

Some devices ie. Galaxy Tablet 10.1 can only send SMS, but cannot call. Some other devices like Asus Transformer don\'t even have SIM card.

How can I detect if devic

6条回答
  •  死守一世寂寞
    2020-12-20 12:40

    Here is what I make to check is SMS available.

    public boolean isAvailable(Context context, Intent intent) {
        final PackageManager mgr = context.getPackageManager();
        List list = mgr.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
        return list.size() > 0;
    }
    

    which is taken from developer.android.com.

    And create an Intent to check like this:

    Uri smsToUri = Uri.parse("smsto:");
    Intent intent = new Intent(Intent.ACTION_SENDTO, smsToUri);
    if (isAvailable(intent)) {
        // do whatever you like.
    }
    

提交回复
热议问题