问题
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.
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/6364136/opening-a-calculator-in-android