I have two Android Application(Application A,Application B) as shown in below figure.
I want to call application B by clicking on Button from first Application A and when Application B launches then the text box will contain the text which I want to pass from Application A.
**Note-
I have access of Application A so I can modify the code of Application A . I have no access to application B.
I have seen many post on Stackoverflow.com and other sites that explain passing data to second application but I saw it is only possible when you have access to modify the code of both class. Here in my case I have no access to Application 2, It is just a APK which is installed on my phone.
I want to just implement like we did in automating a web page through Selenium where we can access a text field and enter value in that text field and .
Application B only for example purpose. It can be any Application having text boxes.
Actually I want to automate the login process of an application(Applicaion B) with the help of Application A .Application A have a number of credential and by selecting a credential from Application A it will launch the Application B and enter the credentioal to Login screen of Application B .
**
Hope I am able to explain my problem.If some more input require I can explain.
You have 2 options:
Application B expects an input (via intent). Then you can launch the app B and pass the value via intent:
intent.putExtra("Key", "Your data here");
You need to know which key the application B uses, otherwise you can't do this.
Application B doesn't expect an input. This is not easy and requieres root-access to the phone:
With the permission INJECT_EVENTS it is possible to type text or send clicks to any window. You can do this:
Instrumentation m_Instrumentation = new Instrumentation();
m_Instrumentation.sendKeyDownUpSync( KeyEvent.KEYCODE_B ); //send key B
you can find more to this topic here. If you need help to compile your app, these 2 links will help you: How to compile Android Application with system permissions, Android INJECT_EVENTS permission
Pass the data to the below intent.
And then get it from the other app.
PackageManager pm = context.getPackageManager();
Intent appStartIntent = pm.getLaunchIntentForPackage(appPackageName);
context.startActivity(appStartIntent);
I don't think this is possible as you do not have any control over the application B.As there are several ways of sending data to application B from A(intent,Content provider and Broadcast recievers etc) but you do not know will B accept those values or not and will manipulate the views according to the data you have sent from A as you have no control over the B.
i'm just gonna give you a heads up in order for you to pass data between two application which you have control over them, then you should use intent for example
intent.putExtra("MyData", "This is a data ");
and in your other application use this to get this data
Bundle extras = getIntent().getExtras();
if (extras != null) {
String value = extras.getString("MyData");
myText.setText(value);
}
Unless another application has set up an intent to receive another application's value, it can't be done. If you have to do it, reverse engineer B's APK, then add implicit intent to handle forms of data you need and create a newer APK
If you're trying to write tests or do something in an automated fashion (similar to WebDriver scirpts) you can use MonkeyRunner http://developer.android.com/tools/help/monkeyrunner_concepts.html but that connects remotely to a device over adb from a host computer.
Depending on how application B populates the data in those input fields you may be able to interact with application B's content provider. You'd probably want to communicate with the author of Application B in that case.
Starting from API 18 there is UiAutomation class, which can send custom events to other applications without need of INJECT_EVENTS permission.
For more information see http://developer.android.com/reference/android/app/Instrumentation.html#getUiAutomation()
Related
I want to send an object between two apps .For instance , you can imagin ,there are two apps which calls app A and app B.App A is running and app B should send an object to app A and after reciving the object by app A , app A shold response that I recive the object .
I study several web site but unfortunately I can't understand many thin ,just I understod , there is a simple way for doing this whit SharedPreferences class. I don't want to use this way becuase I don't want the object to save ...
please guid me.
Thanks.
You can use Intents for that. Just send an Intent for Activity Z of App A in App B and put your parameters in the Extras bundle.
In Activity Z do the same with the reply for Activity Y of App B.
I've been searching and I couldn't find a topic that could clarify me 100%.
My question is: How can I launch an android's app preferences activity (from Contacts, Messages, ...) on my own app?
I give an example:
Imagine I'm developing an app which allows the user to quickly access to Message's Settings. I don't need to send or receive any information, I only need to open the activity, create a shortcut for it.
Someone knows if this can be done and even opening specific locations of the apps?
You don't need to know any specific locations or specific apps for these actions, simply look into Intent.ACTION_PICK.
Picking a Contact: get contact info from android contact picker
Picking a picture: How to pick an image from gallery (SD Card) for my app?
The best answer in this thread has the solution:
android: how do i open another app from my app?
Also check:
http://android-developers.blogspot.com/2009/01/can-i-use-this-intent.html
To open settings, you can try:
startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS, 0));
There is no difference in writing in code an Explicit Intent which will go to a specific activity of your app and using the same format to go to a specific activity some other app. A few things to be aware of: (1) The receiving activity may be expecting particular data and fail otherwise. (2) The standard apps you are considering like Contacts, Messages while you can find the source for them in the Android Open Source Project (AOSP) may be changed by the manufacturers so that the activity names and necessary extra data could be different.
In order to maintain as much compatibility between all of the different Android manufacturers, you should stick to the standard implicit intent with the appropriate action/data.
I read this question and another question and I understand how to launch an application from another application (Let's call the other application LauncherApplication). However, my goal is not only to launch an application, but to use its functions, so I suppose the LauncherApplication should start an activity using an intent (explicit or implicit).
I should know the data and the actions the installed applications react on and I should add these information to an intent instance before starting it. I wish LauncherApplication allows the user (not the developer) to configure this intent, but how do I know in advance the parameters to put in an intent for the installed applications?
I should implement the "LauncherApplication* in order to allow the user to construct an intent via a graphical interface. Or I could make my application supports the addition of plugins: in this way, I could create a plugin for each installed application, where each plugin could be responsible to manage the configuration of the intent concerning the application associated with it.
UPDATE (added details). In particular, the LauncherApplication should be a service with a speech recognizer enabled, so the user may start an application uttering specific keywords: as well as launch an application, the user should be able to close it and use its functions.
For example, I could have installed an application ((Let's call it LibraryApp) to search for available books in a library; this application could have the following functions:
Search for a book (this function may return if the book is available, it has already been loaned or if it was booked by someone else).
Reserving a book (this function should return the completion of the reservation).
In this way, when I pronounce, for example, the words "start LibraryApp", then the LauncherApplication service should launch the LibraryApp application. Once the application is launched, the service should be able to send commands to it to use one of the available functions (search for a book, reserving a book).
How can I send commands to application that is already active, in order to control it?
how do I know in advance the parameters to put in an intent for the installed applications?
You talk to their developers. There are typically zero "parameters" on an Intent to launch the launcher activity (or activities) of an application, since home screens do not put such "parameters" on the Intent.
background:
i've noticed that for regular activities within, it is possible for any application to open the activities of my app .
question:
is it possible to allow only my own app (or apps , or package) to send and receive intents inside the same scope , so that other application won't be able to receive them or interfere with the flow of the app?
example:
suppose i have a broadcastReceiver that listens to some kind of intent , but this intent is only meant to be used by another service/activity that resides either inside my app , or inside another app that i've created , but i don't want others to be able to use this intent.
please help me.
setPackage()
Set an explicit application package name that limits the components this Intent will resolve to. If left to the default value of null, all components in all applications will considered. If non-null, the Intent can only match the components in the given application package.
or you can use setSelector() , but not both.
suppose i have a broadcastReceiver that listens to some kind of intent , but this intent is only meant to be used by another service/activity that resides either inside my app , or inside another app that i've created , but i don't want others to be able to use this intent.
In addition to Reno's fine answer, for your specific requirement quoted above, use LocalBroadcastManager. Not only do you get the security you seek, but it is more efficient. LocalBroadcastManager is available in the Android Support package and AFAIK should work going back to Android 1.6. Here is a sample project using LocalBroadcastManager.
If I want to create custom address book (which overrides my phone's default address book), and if I want it to be used by all applications, what should be my intent-filter? Does Android allow me to do such a thing considering the fact that such a third-party app could potentially be malicious?!
And, if I want to have yet another address book application, I suppose the second app also has same intent-filter, isn't it? How does the framework decide which app to pick if I click on Contacts button when making a call? In other words, how does the framework resolve intents in case,there is a conflict between multiple intent-filters?
You can replace any application on Android platform, even Home. Android documentation explains everything there is to know about Intents and Intent Filters and there is a section called Intent Resolution that answers your question. Intent Resolution section for Intent class has some additional information.
As far as I can tell Android doesn't try to resolve a conflict. It ask the user which application to run and gives them the choice to mark this Activity as the default for this Intent. They give an example about mail app here.
While Mr. Smiljanić is basically correct, there is no Contacts application in Android for you to replace. There is Dialtacts, which is the application supporting the contacts, call log, and dialer. That application cannot be replaced, mostly because the dialer cannot be replaced.
So, while you may be able to override some intent filters and get control on some contacts-related requests, you will be unable to get the contacts portion of Dialtacts overridden, which will confuse users.