Is it possible to close an activity which hasn't been started by your activity?
So, suppose I have an app which has MainActivity. My Mainactivity wants to close CNN app that is installed on my phone (and probably running in background). Is it possible?
To do that, you'll either need to have a rooted phone, OR, have created the other application yourself (so you could write code to close itself down when getting a specific broadcast)
Seeing as you want to close the CNN app, which im guessing you haven't created yourself, then no, it's not possible.
An application can't simply manipulate other applications lifecycle.
Mostly no. Because of android security model you cannot have direct access to third party activities data/methods. You could only close 3rd party activity via intent in this activity will support this kind behaviour.
Related
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
I think we have three apps, and all of them are open and we know the process name. How can I switch from one app to another app, also keeping in mind that another app has opened a intent, and I do not want to go to another app with opening an app launcher, just switching or making another app at front.
I want to make another app on front, for example if Internet is background, I make it at front.
Make the main activity for your applications singleProcess, if the application is already running it will be bring to the front. you can also, implement a custom BroadCastReceiver to start the application using its package name.
I need to "lock" a user into an application. The device's sole purpose is to use this application, and so it is not feasible to allow the user to navigate the device for any other reason. What is the best way to make sure that the applications Activitys are always in the foreground, and if not, launch the main Activity?
Now I know this goes against everything about the typical Android application development, but these devices are going to be specifically used for this one application.
What is the best way to determine if any of the applications Activitys are in the foreground, and launch one if not?
What is the best way to make sure that the applications Activitys are always in the foreground, and if not, launch the main Activity?
You don't.
Make your activity be the home screen, and they can't go anywhere. And roll your own firmware, so that the user can't safe-boot the device and remove your home screen.
I will probably use a service which gonna check using a flag as example for a living activity.
Look here for more detail about how to do : http://developer.android.com/guide/topics/fundamentals.html
See the answer to this question: basically you must implement a second app that captures home intents and simply re-launches your primary application if it is ever closed.
In reference to what CommonsWare was saying, you could actually partially brick the device. I've done it on accident where I've bricked the recovery menu, but not the actual regular boot. This is a terrible idea of course and should not be used practically.
We want to use Android mobile for dedicated application. Can somebody suggest how can we make it happen.
Here are the requirement:
The phone when started, should launch our application., so the user cannot launch any other application. The application will be a 1D barcode reader.
The application should be live as long as the phone is up and running, user cannot close the application at all.
Thanks for your help.
Regards,
Manish
Android after boot is complete sends a bradcast intent:
android.intent.action.BOOT_COMPLETED
if you listen for this intent, you can launch a service that in turn launch your activity.
In the Activity you have to take care of the user's interactions that explicitly close the activity, like home button, back button and camera button press.
Setting your activity to be full-screen also should prevent the user to use the notification bar to interact with notification like those from market-app that can close your activity.
Finally, your activity can be killed by the system by various and uncatchable reasons: in those cases, the service that first launched your Activity comes in handy, as it can periodically monitor the general state of the application and relaunch components as needed.
Check out the new Android Enterprise solutions for your use case.
https://developers.google.com/android/work/overview
Its well documented. You can either use
Android Management API to provision the devices and apply policies to the device which will be applied to the device using Android's Device Policy Controller (DPC) or,
Use Google Play EMM API and develop your custom DPC
It depends upon your use-case really, but the first solution set should serve your purpose
I'm afraid there's no single answer to this, but you need to work on multiple fronts.
One of these fronts is preventing user from running other applications: for this there are applications sold on Android Market that can put other apps of your choosing behind passcode.
You need to combine this with automatic launch, but I don't yet know how to do that.
When a user tries to launch an application I want to suppress that application and then call another application. Example I want the user to authenticate himself before launching a particular system application (settings application etc). The authentication application should pop up every time the user launches the settings application
I know you will have to use broadcast receivers and intents but have no clue how to do it.
Sounds like you should create a "lib" project that have public interfaces that you can use.
Then share them between the apps instead of trying to execute another app?
But what I know this is not possible to actually execute up another app, since this then gives dependency to something that you don't know if it is installed. It must already been started if the intents should work.
Also like the answer before, it could be used for abuse.
Look at this link for more information:
http://mylifewithandroid.blogspot.com/2007/12/playing-with-intents.html
I sort of hope this isn't possible... Launching a different application from the one the user actually clicked? Leaves the door open for abuse.