I am looking for a way to automatically open an application on Android. Something like QTP on windows. I read about quite a few testing tools for Android that need the phone to be connected to the laptop via USB. Is it possible to code an android application that can open another specific application on the device automatically?
I understand that if it is my application or an open source one, I can get the UI element and perform click or type into it automatically using code but how can I access UI elements of other apps on the device.
Example: My app should be able to open my phone keypad and type in a number or open an app like Truecaller and type into the textview on main screen? Something like web automation but for Android device. Any help would be appreciated! Thank you!
You can use Intents:
//consider context as being the Context of your current app
PackageManager packageManager = context.getPackageManager();
Intent intent = packageManager.getLaunchIntentForPackage(PACKAGE_NAME);
context.startActivity(intent);
device.wait(Until.hasObject(By.pkg(PACKAGE_NAME)), 10000); //this is a UiAutomator method to wait for the application to be started (or 10 seconds).
You can also use solo UiAutomator methods: open the apps menu, click on the app icon. You can see an example here
Related
I have three existing apps. Now i want to combine all the three into single app.
Say i have three button, when i click button 1 then app 1 should run. And when
button 2 is clicked app 2 should run. Is it possible in android studio? have
have tried searching but nothing helped.
From this SO start application knowing package name. Just use these two lines you can launch any installed application whose package name is known:
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.example.abc");
startActivity( LaunchIntent );
for the unknown package name
PackageManager pm;
pm = getPackageManager();
// get a list of installed apps.
packages = pm.getInstalledApplications(0);
I'm going to preface this by saying I do not have any experience with Android Studio. Hopefully it bears some resemblance with its terribly simplified counterpart App Inventor.
Anywho, I would create an independent main screen (activity?) that has 3 buttons on it and paste the three existing apps' code into other screens in the same app. Each button would open its corresponding screen/app through opening a new activity.
Got the solution. I just converted the three applications to library and imported them into the main app. Now i can call any activity from any of the three app any time as required. While using package manage all the three apps would have to be installed separately. Thank you coder and himty for sparing some time to answer my question. But still i have a problem. I am actually working on watch faces. Even though i can launch any activity, i still can't change the watch face. Tried Wallpaper but we can only open the face picker & cannot set the watch face.
ComponentName unique=new ComponentName(MainActivity.this,BlackOwlBlue.class);
Intent i=new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER)
.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT,unique)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
I am trying to make a small application that can launch an application, not usually shown in the app drawer. This application is generated by the system and is carrier specific. It belongs to the package com.android.stk - for those of you who don`t know it is the SIM Toolkit application. The SIM Toolkit application itself can not be launched, but when I insert my sim card, it creates a carrier specific application - In my case: Dialog Services, which can be run to make changes to sim settings.
The problem is that the package name for the Dialog Services app is still com.andorid.stk . All I want to do is open up that app. Is there any way to do this... Possibly search for all apps within com.android.stk and selecting or launching that one...
I am relatively new to Android dev, so All help is appreciated.
You can launch any installed application whose package name is known:
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.andorid.stk");
startActivity( LaunchIntent );
I am trying to open a different, already installed android application within another, on click of a button. The new application should be opened in a part of the screen within the calling application.
Currently, my code creates a new intent and runs the called application in that. the calling application disappears. Here's my code:
b.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
PackageManager pm = getPackageManager();
Intent intent = pm.getLaunchIntentForPackage("com.ritwik.camera");
startActivity(intent);
}
});
Ideally, it should open as a part of the same screen, without sidelining the parent(calling) application. How do I do that?
When you start an Intent to execute another application (i.e. because you are implementing a launcher or a main menu replacement) you are actually asking android to execute the application identified with a specific package (or the one satisfying some specific constraints, like the ability to handle images, videos, etc), without any clue or reference about the Activities it contains (nor the ability to get any...).
Therefore I don't think that what you are trying to achieve is possible with the current version of the OS (unless some vendor is providing extensions to do just that, see the comment by Pratik).
The new application should be opened in a part of the screen within the calling application.
This is not possible with conventional third-party application UIs.
AFAIK, the split-screen feature (Adaptive UI) is supported from Android 3.0 onwards.
That has nothing to do with embedding the UI of third-party apps into your own.
So I didn't get what you meant to say by "it's not possible with the current version of the OS"
It is not available on any stock version of Android released up through March 26, 2013 at 9:50am Eastern Time.
Certain device manufacturers, like Samsung, have extended Android with multi-window capabilities. However, the control over those windows lies with the user and the (modified) OS. Unless there is something in their S-Pen SDK for this, you have no way of starting another window.
Android also has RemoteViews, which is a means of passing a simplified UI between processes. Using this, it is possible for one app to embed RemoteViews published by another app. You see this with app widgets on the home screen, for example. However, both apps have to be written with this in mind, such as an app publishing an AppWidgetProvider to supply app widgets to home screens.
As far as I know, this is NOT possible. You can only launch the new activity, but you have no control of it.
EDIT: Some devices offer this possibility using Cornerstone or similar frameworks, but I haven't seen an option for developers to use this for their own apps.
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.
I am trying to automate android app(Relocation services)using robotium. In this app there are media section and email and phone native dialer options so when i click on any of this option(Video, audio, phone, email) it takes you to the native app(video,audio, phone, email) of the phone. So how to handle external application activity using robotium(Like click on back button to come back to my app, or close native camera or video app to come back to my app)
Any answer will be great help.
You can only access your own app from within the instrumentation framework.
There are some options:
remove the default apps and add some fake apps to handle the intent (see https://github.com/bryanl/FakeCamera) for an example. to remove the app: http://oneclickandroid.blogspot.de/2009/01/how-to-remove-defaultpreloaded.html
resign the apps you want to control with your key so you can instrument them (see http://code.google.com/p/robotium/wiki/RobotiumForPreInstalledApps)
install your app with system permissions ( Android INJECT_EVENTS permission ), but haven't tried method yet
Sorry to bump this...
I've just put the camera stub and gallery stub that I made / use on the play store... thought might be of use to you / others for testing the camera and gallery in automated tests :)
https://play.google.com/store/apps/details?id=com.hitherejoe.CameraStub&hl=en
https://play.google.com/store/apps/details?id=com.hitherejoe.GalleryStub&hl=en_GB
I think, Using Robotium you can't access other application resources from your target testing application.
Just use Instrumentation for this,
Instrumentation inst = new Instrumentation();
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
But be sure if you are doing this in Activity then put this in separate thread for run this code..