calling one app from another, Android sdk? - android

My question is, is it possible to call one app from another?
It would be very helpful if anyone had an answer or solution.
-Chris-

Yes, by using intents.
For example:
final Intent intent = new Intent();
intent.setAction(Intent.ACTION_MAIN);
intent.setClassName("com.example.theotherapp", "com.example.theotherapp.MainActivity");
startActivity(intent);
This is called an explicit intent, because you're explicitly stating which component should respond to it. You can also use implicit intents, in which you specify what kind of component you expect and the OS and/or the user selects the most appropriate one.
If you can choose, implicit intents are preferred.

You should take a look at http://developer.android.com/guide/topics/fundamentals.html, more specifically at the "Application Components" section.
There are many ways to make two applications talk to each other - and they're explained there.

Related

Im looking to start a specific application using intent in android studio

I am looking to start a specific application(Dictionary app) from my app. Using intents, how would I go about launching that specific app and use it to look up the word.
There are implicit intents and explicit intents, you want an explicit intent to get your desirable.
Here is how you can do it.
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.example", "com.example.MyExampleActivity"));
startActivity(intent);
in the setComponent method your Dictionary app information should go in.
CommonsWare addition to this answer,
Using an explicit Intent to talk to a third-party app is rarely the right thing to do. This code will break if the activity is not exported, or requires permissions, or the developer refactors the code and changes the class name or package, etc.
If the author of the app is documenting that your recipe is the correct way to work with that activity on that app, then that is fine, as the developer presumably intends to support this use case.

what is difference between public and private Intents

I know that public (named) intents that are registered with the system and can be called from any application and private (anonymous) intents that are used within a single
application. please can anyone give me an example for better understanding.
Thanks in advance
Sorry no time to write a full answer, but you can create custom permissions in order to sign your Intents & BroadcastReceivers.
When you use these custom permissions, only apps that have been signed with the same signing key, and include that custom permission, can see these Intents.
This question might help you:
How to use custom permissions in Android?
#Commonsware explains the issue really well in a recent blog post:
Don't have an Accidental API - The CommonsBlog
The Android documentation does probably the best job of explaining it, here is a relevant snippet:
There are two primary forms of intents you will use.
Explicit Intents have specified a component (via
setComponent(ComponentName) or setClass(Context, Class)), which
provides the exact class to be run. Often these will not include any
other information, simply being a way for an application to launch
various internal activities it has as the user interacts with the
application.
Implicit Intents have not specified a component; instead,
they must include enough information for the system to determine which
of the available components is best to run for that intent. When using
implicit intents, given such an arbitrary intent we need to know what
to do with it.
This is handled by the process of Intent resolution,
which maps an Intent to an Activity, BroadcastReceiver, or Service (or
sometimes two or more activities/receivers) that can handle it.
Explicit intents you use in your activity to start internal activities.
While implicit intents are used often used to launch other activities like when you want to share a link or email something, you send out an implicit intent and let the user decide the email client to use to send the email or to share the link.
There are some instances where you might want to use an implicit intent to run an internal component of your app, because it seems to be more stable.

Opening a Calculator in Android

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.
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.

Android: Proper way to reuse my app's activities?

What's the proper way for other people to reuse my Activities? Should they hard code the intent actions in their app or is it customary to provide them with a jar file enumerating my app's intent actions? Is there a less tightly-coupled way to lookup the intent actions?
First of all, take a look at openintents.org and see if there's any match to what your activity does.
Secondly, documentation is always a good idea.
Having the intent details hardcoded in their applications should work just fine. After all, the intents are part of your public interface and shouldn't change.
Your applications manifest should announce what sorts of things your activity can handle, via intent-filters. Outside users can read the manifest to determine what actions you support, and invoke them via action intents.
See intents and intent filters for more details.

Android Override Explicit Intent

My app needs to have a intent-filter that responds to a Intent that has it's component set (a explicit intent.) Here is a example.
Intent i = new Intent();
i.setClassName("com.compareeverywhere","com.compareeverywhere.ScanActivity");
startActivity(i);
Just a simple intent-filter will not do - because the Intent is made for a specific component (Activity,) it just launches that without looking for intents at all. Is there a way to do this?
Thanks, Isaac Waller
P.S: Please don't reply "No."
No.
:) That being said, imagine what would happen if Android allowed people to hijack Intents for specific components. Don't like a competitor's app? Just have yours hijack his main Activity with your own to display porn. Intents can specify specific components specifically because the authors don't want others to be able to replace them.
You have two options. If this is your own code, replace it with a generic intent, or if it belongs to someone else, contact them, and ask nicely for them to change it to a generic intent along with some good reasons why that is necessary.

Categories

Resources