【问题标题】:How to Open default calculator如何打开默认计算器
【发布时间】:2017-10-09 11:14:09
【问题描述】:

我使用下面的代码来显示默认计算器。但我得到了 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
                }

【问题讨论】:

  • 有大约 10,000 种 Android 设备型号。没有人必须有计算器。那些这样做的人可以拥有他们想要的任何计算器应用程序。没有人必须有com.android.calculator2com.android.calculator2.Calculator 不必是导出的活动,更不用说启动器活动了。
  • @AmjadOmari 感谢您的帮助。它对我有用。
  • @ModularSynth 检查 Amjad 分享的答案。解决了我的问题
  • @ModularSynth 是的。但是我们正在开发一个应用程序,用户不需要在应用程序中搜索计算器,他们可以直接点击计算器按钮并进行计算。它将节省我们的用户时间

标签: android


【解决方案1】:

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

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

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2011-07-01
  • 2012-02-04
  • 1970-01-01
  • 1970-01-01
  • 2018-03-18
  • 2011-06-02
  • 2021-03-26
相关资源
最近更新 更多