I am developing an application which the user taps on EditText
, it displays the android calculator, so the user is able to do arithmetic operations.
I would like to retrieve the final value when the user presses the equal button in the android calculator and display it. Is that possible using the standard android calculator?
The code to open the calculator is the following:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setComponent(new ComponentName(CALCULATOR_PACKAGE, CALCULATOR_CLASS));
startActivity(intent);
where,
String CALCULATOR_PACKAGE ="com.android.calculator2";
String CALCULATOR_CLASS ="com.android.calculator2.Calculator";
Any ideas or suggestion about how to retrieve the final value from the calculator?
Thanks
It's not possible using the standard calculator, but that calculator is open source, so you could create your own calculator. The source contains a class called Logic (Logic.java); if you update the method evaluateAndShowResult() to automatically paste the result to the clipboard, and then do a paste in your app, you'd be ready.
As an alternative, if you really don't need the calculator's UI, you could just take Logic and trash the rest.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With