Opening a Calculator in Android

2019-02-28 01:06发布

I'm looking to open a calculator from within my Activity. Here's my code right now and it works:

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

I would like to make this an implicit call because I don't know what calculator the use would like to use and I would like to leave the option open to receive a value from the calculator, which the android one apparently doesn't do. I haven't been able to find a good example of how to implicitly ask for a type of application.

I've looked at http://www.openintents.org/en/intentstable but I guess I don't completely understand how to use that site.

I think I understand the intent of intents, but maybe I just don't have a firm grasp on how to use them.

2条回答
来,给爷笑一个
2楼-- · 2019-02-28 01:14

What you have is probably the best you can do. I just checked the AndroidManifest.xml for com.android.calculator2.Calculator and it doesn't listen for any other intents.

查看更多
做个烂人
3楼-- · 2019-02-28 01:30

I'm looking to open a calculator from within my Activity.

Write a calculator activity.

Or, find an open source calculator app and integrate its calculator activity.

Or, find a calculator app with an official API, use it, and lead the user to download it from the Market the first time they try launching the calculator feature.

Here's my code right now and it works:

Yuck.

I would like to make this an implicit call because I don't know what calculator the use would like to use

Beyond that, the calculator you are hard-wiring in may not even exist on the device. Device manufacturers are welcome to replace the calculator, and Google is welcome to refactor the calculator to not use that package or class name.

Please only use activities that are documented and supported to be linked to. If you have to call setClassName() on an Intent, you already failed.

I haven't been able to find a good example of how to implicitly ask for a type of application.

There is no way to do this, any more than there is a way to implicitly ask for a recipe book, or a currency converter, or a shiatsu massage guide app, or a first person shooter game.

查看更多
登录 后发表回答