检查设备是否可以拨打电话

时间:2014-08-04 09:34:17

标签: android android-intent package-managers

我通过PackageManager检查功能

final PackageManager packageManager = context.getPackageManager();
        final Intent intent = new Intent(Intent.ACTION_CALL);
        List<ResolveInfo> list =
                packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
        return list.size() > 0;

但无论如何结果都是假的。申请是在平板电脑和手机上,但结果是一样的。哪里错了?

1 个答案:

答案 0 :(得分:3)

你应该试试这个:

PackageManager pm = this.getPackageManager();

 if (pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
     System.out.println("horray");
 } else {
     System.out.println("nope");
 }

编辑:要检查Skype是否已安装在设备中?

通过以下方法传递Skype URI。

private boolean appInstalledOrNot(String uri) {
        PackageManager pm = getPackageManager();
        boolean app_installed = false;
        try {
            pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
            app_installed = true;
        }
        catch (PackageManager.NameNotFoundException e) {
            app_installed = false;
        }
        return app_installed ;
    }