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.
Related
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()
Context
Our app shows an HTML flashcard to the user.
We have added several layers of "filters" to satisfy different groups of users:
To satisfy chess enthusiasts, we convert any {FEN:rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 1 2} block to an HTML table representing a chess board with pieces at the right position
To satisfy Chinese language learners, we convert 字 to <ruby>字<rt>zì</rt></ruby>
...
Original HTML → Chess transformation → Chinese transformation → ... → Final HTML to display
Problem
The number of filters is growing, leading to problems:
Slower rendition
Heavier download
Bigger source code to maintain
More bugs/crashes
Maintenance burden
Question
So, we would like to make these separately installable apps.
For instance, a chess+Chinese enthusiast would install 3 apps:
TheApp
TheApp Chess plugin
TheApp Chinese plugin
TheApp would automatically discover what plugins are installed, and call them in turn (order does not matter).
I was thinking of using an intent THEAPPTRANSFORM, but how can I receive the list of apps that have an <intent-filter> for THEAPPTRANSFORM, and call them all in turn?
Speed is a major requirement. I have read that Intents are 10+ times slower than direct calls... would Parcelable help here?
If impossible, is there any other solution?
To know apps which have a broadcast reciever with THEAPPTRANSFORM as filter, you can use below code
PackageManager pm = getPackageManager();
Intent intent = new Intent("THEAPPTRANSFORM");
List<ResolveInfo> info = pm.queryBroadcastReceivers(intent, 0);
for (ResolveInfo resolveInfo : info) {
Log.e("apps", "packages = " + resolveInfo.activityInfo.packageName);
}
You need a dynamically installed plugin which is not part of your application. I think you have a few options for this.
Solution 1: Scripting
Ship a scripting language interpreter with your app. (eg. ruby - http://ruboto.org/). Create an interface for executing these scripts. Make a central database of such scripts, or load them from external storage. Now, you can execute these scripts and get the required result.
Solution 2: AIDL
Use a remote service in the plugin apps. Provide an AIDL for third parties to develop apps with a remote service with that AIDL. Such services should also conform to an intent filter defined by you. Now you can use packagemanager to find such services, select one and connect to it. Now you can call all the AIDL methods. This will be inter process communication using binder, for your application this will be a synchronous call. (see this SO question for details - Access remote service in different application)
Downside to this approach is that all these services need to be running when your app is running, so you have to handle the starting/stopping of these services. It will also affect the power consumption if the services are running in the background.
Solution 3: Broadcast/receiver
Third party installed apps that have a broadcast receiver with an intent filter for custom intent defined by you. Also, your app needs to have a broadcast receiver with a custom intent that the plugins can call with the result. Now, say you want to call a third party plugin for some transformation, you have to do this:
Use packagemanager to find all the third party apps conforming to
your custom intent. Send a broadcast with extradata about
transformation. Handle the transformation in the broadcast receiver of
the plugin app. Once transformation is done, send a broadcast with
result to the original app.
This option is entirely asynchronous, and it may take any amount of time to execute with no guaranties.
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've built an app called xLancer (https://market.android.com/details?id=kz.jay.xlancer.activity) that retrieves job listings from Elance. Now i want to implement a feature that would remind me to bid on a project at a later time. Instead of reinventing the wheel i want to launch any external TODO/Task manager app. But now i am stuck, i don't know which URI or action should be specified, so far i've only used intents to call my internal activities by specifying class name explicitly.
So the question is: how can i know which URI/action should be specified?
Look here, I didn't see any Todo/Task intents there though....
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.