如何打开默认计算器

时间:2017-10-09 11:14:09

标签: android

我使用下面的代码显示默认计算器。但我得到activityNotFound异常。

 public static final String CALCULATOR_PACKAGE ="com.android.calculator2";
public static final String CALCULATOR_CLASS ="com.android.calculator2.Calculator";

 Intent intent = new Intent();
                intent.addCategory(Intent.CATEGORY_LAUNCHER);
                intent.setAction(Intent.ACTION_MAIN);
                intent.addCategory(Intent.CATEGORY_LAUNCHER);
                intent.setComponent(new ComponentName(
                        CALCULATOR_PACKAGE,
                        CALCULATOR_CLASS));

                try {
                    startActivity(intent);
                } catch (ActivityNotFoundException noSuchActivity) {
                    // handle exception where calculator intent filter is not registered
                }

1 个答案:

答案 0 :(得分:0)

这个意图应该让你的工作完成

Intent i = new Intent();
i.setAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_APP_CALCULATOR);
startActivity(i);