Search code examples
javaandroidandroid-intentandroid-activityactivitynotfoundexception

Intent.CATEGORY_APP_CALCULATOR: ActivityNotFoundException


I'm trying to open the default calculator app in a android application. Two calculators are installed in device: default android calculator and Google Calculator.

Intent calc = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, Intent.CATEGORY_APP_CALCULATOR);
startActivity(calc);

This code is throwing an ActivityNotFoundException and shows this in logcat:

system_process W/IntentResolver: resolveIntent failed: found match, but none with CATEGORY_DEFAULT

This code have the same behavior:

Intent calc = new Intent(Intent.ACTION_MAIN);
calc.addCategory(Intent.CATEGORY_APP_CALCULATOR);
startActivity(calc);

It's a Android bug? How to open the application chooser, to let user select the default app?

Stack Trace:

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)

Solution

  • It seems like the way, that documentation points to doesn't work. Nevertheless, this code will normally open default calculator app.

    Intent intent = new Intent();
    intent.setClassName("com.android.calculator2", "com.android.calculator2.Calculator");
    startActivity(intent);