I'm writing a basic application. One of the features I'm interested in trying to do is to launch another app, INSIDE the app already running.
Eg. I have an app with 3 menu options, 1 and 2 do certain tasks as part of this parent app, menu option 3 launches another app that's installed on the phone.
I'm not sure if this is possible?
This is possible with the Intents mechanism.
The exact Intent you'll have to write depend on various factors:
do you have to provide some data to the launched application?
do you target a specific application or do you want to let the user choose the application he prefers for that task (in case he has several applications able to do what you need)?
do you want to ensure that the application is available? (that would be better)
do you know if the other app provides specific intent-filters to do some tasks?
Edit:
Then, you should be able to start the second application with the following code:
Intent i = new Intent(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_LAUNCHER);
i.setPackage("com.otherapp.package");
startActivity(i);
Place this code in the OnClickListener of your button and that should be enough.
Related
Is there a way to find out from the just-opened app, from within, what were the intent details used to open the current app?
Sample scenario:
The app can have multiple activities, I would like to know which one was requested when the app process starts, e.g. from Application.onCreate.
Currently, I app developing an application which uses share intent. but when I share a file to my app, my application starts another process.
Steps to reproduce.
start the application.
go to gallery/file manager.
select a file and share to the current application.
Show list applications are running.
Result:
My application starts in two different processes (Please see the screenshot)
I got the answer. It needs android:launchMode="singleTask/singleInstance" in the activity.
I have two apps on the play store . Both of them handle an intent and run a service based on it.
However I do not want them to compete and if both are installed I only want App A to show in the Android App chooser and not App B.
How would I keep App B from trying to handle the intent if App A is installed?
Android handles intents internally so when you say an activity is registered for handling an intent it will most likely be via Action field.
If you want two activities to have the same action and to suppress one Activity from showing in Chooser, then it is not possible unless you modify the Android OS.
However I do not want them to compete and if both are installed I only want App A to show in the Android App chooser and not App B
Activities do not "compete" for starting up, its usually the user who chooses which activity to start when an action is specified. So if you want AppA to only show in the chooser, you can declare a different action for AppB.
Hope this helps!
This is an odd question, but is there any way to run two separate applications inside one app? So, for example, run another application in a view inside of another app? Is this possible? If so, how is this done?
Thanks in advance!
This may be done although it may go against the recommended way of doing things in Android
Android launch app inside view
How to create android app with app widget in single application
An easier alternative may be to launch an intent with the package address:
Intent i = new Intent(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_LAUNCHER);
i.setPackage("com.otherapp.package");
startActivity(i);
Launching Android app, within an app?
Launch an application from another application on Android
However, please note that, technically, the other app is still in its own process although you it appears to function within the original app.
Launch another application INSIDE an application in Android
WeChat has hundreds of Mini-Programs can only open via WeChat apps. But that mini-programs is web-based view. Here the official video
https://www.youtube.com/watch?v=OKcdUT3ZSwA .
Is it possible to run an application from inside another application? What I want to do is write an app which allows you to chose an app to start, and then displays the activities of this app inside a view.
So in landscape mode, it should look something like this:
The idea behind this is:
I want to be able to start and run a third party activity next to my own activity, and I want to be able to create individual makros with my activity that are controlling the third party activity.
Basically, something like this:
Start third party activity from inside my app
Start makro recording
Do something in third party activity
Stop makro recording
Use makro whenever you wish
So how can I start and control another activity from inside my own activity?
Unrooted:
Sadly, what you want to achieve does not seem to be possible without rooting the phone, because you can only interact with other apps via intents. Since developers decide how their apps react on specific intents, creating macros this way is nearly impossible.
With rooted phones:
You may want to create a list of all installed apps, you can use
getPackageManager().getInstalledApplications(PackageManager.GET_META_DATA);
to retrieve a list of all installed apps.
If the user now selects an app, launch it via an intent and create a system overlay to get all touch/key events (and let the user stop the macro). You can find a way to do this here. Store the x/y-values of the touch-events.
You can recreate the events using MotionEvent#obtain.
Now comes the part where you need a rooted phone (the permission INJECT_EVENTS). Launch the app and inject the events so your macro gets executed. Samplecode:
Instrumentation m_Instrumentation = new Instrumentation();
m_Instrumentation.sendPointerSync(motionEvent);
You can find more information about injecting (also keyevents) 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
It's not possible to start an application in a View, but you can launch an app from within your app:
Intent i = getPackageManager().getLaunchIntentForPackage("com.package.ofapp");
startActivity(i);
//EDIT to your updated question:
After starting the activity from the above code, one way you could start/stop the macro at any time in the new app would be to create a small view overlay on top of the screen.
This overlay would be on top of ALL activities.
Check out the following link: Creating a system overlay window (always on top)
You could write code to start the macro when the View is pressed, and then if the button was pressed once and the user presses it again, stop the macro. This would be in the onTouchEvent() method.
Yes, I think it's possible as a app named floating apps does that (WITHOUT ROOT)
Only using some adb commands
https://play.google.com/store/apps/details?id=com.lwi.android.flapps
Yes its possible if you use Intents. They allow you to move between screens and to launch another different functionality inside the same app. visit coursera for more tutorials on intents