【发布时间】: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.calculator2,com.android.calculator2.Calculator不必是导出的活动,更不用说启动器活动了。 -
@AmjadOmari 感谢您的帮助。它对我有用。
-
@ModularSynth 检查 Amjad 分享的答案。解决了我的问题
-
@ModularSynth 是的。但是我们正在开发一个应用程序,用户不需要在应用程序中搜索计算器,他们可以直接点击计算器按钮并进行计算。它将节省我们的用户时间
标签: android