-3

I am using below code for displaying default calculator. But i am getting activityNotFound exception.

 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
                }
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Rahul Rawat
  • 11
  • 1
  • 12
  • https://stackoverflow.com/questions/13662506/how-to-call-android-calculator-on-my-app-for-all-phones – Amjad Omari Oct 09 '17 at 11:15
  • There are ~10,000 Android device models. None have to have a calculator. Those that do can have whatever calculator app that they want. None have to have `com.android.calculator2`, and `com.android.calculator2.Calculator` does not have to be an exported activity, let alone a launcher activity. – CommonsWare Oct 09 '17 at 11:17
  • @AmjadOmari Thanks for your help. it works for me. – Rahul Rawat Oct 09 '17 at 11:23
  • @ModularSynth check the answer which shared by Amjad . that solved my issue – Rahul Rawat Oct 10 '17 at 11:36
  • @ModularSynth Yes. But we are developing an app where user don't need to search calculator in app they can directly click on calculator button and can calculation. it will save our user timeing – Rahul Rawat Oct 13 '17 at 09:04

1 Answers1

0

This intent should get your job done

Intent i = new Intent();
i.setAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_APP_CALCULATOR);
startActivity(i);
Akshay Katariya
  • 1,464
  • 9
  • 20
  • Note that this does not match what [the JavaDocs say for that category](https://developer.android.com/reference/android/content/Intent.html#CATEGORY_APP_CALCULATOR). – CommonsWare Oct 09 '17 at 11:17