我正在尝试在 android 应用程序中打开默认计算器应用程序。设备中安装了两个计算器:默认的安卓计算器和谷歌计算器。
Intent calc = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, Intent.CATEGORY_APP_CALCULATOR);
startActivity(calc);
此代码抛出 ActivityNotFoundException 并在 logcat 中显示:
system_process W/IntentResolver: resolveIntent failed: found match, but none with CATEGORY_DEFAULT
此代码具有相同的行为:
Intent calc = new Intent(Intent.ACTION_MAIN);
calc.addCategory(Intent.CATEGORY_APP_CALCULATOR);
startActivity(calc);
是安卓的bug吗?如何打开应用程序选择器,让用户选择默认应用程序?
堆栈跟踪:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] sel=act=android.intent.action.MAIN cat=[android.intent.category.APP_CALCULATOR]} }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1805)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1514)
at android.app.Activity.startActivityForResult(Activity.java:3930)
at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:50)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:79)
at android.app.Activity.startActivityForResult(Activity.java:3890)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:859)
at android.app.Activity.startActivity(Activity.java:4213)
at android.app.Activity.startActivity(Activity.java:4181)
at com.MyActivity.openCalc(MyActivity.java:202)
at com.MyActivity.onOptionsItemSelected(MyActivity.java:191)
at android.app.Activity.onMenuItemSelected(Activity.java:2914)
at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:408)
at android.support.v7.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:195)
at android.app.ActivityThread.main(ActivityThread.java:5461)