I wonder how it is possible to simulate a button click to launch an app through its shortcut? I have seen automation apps such as Automagic (perhaps also Tasker) do this.
Are they using AccessibilityServices? If yes, how would I call such a shortcut -do I use "performGlobalAction()"?
Edit:
What I really after is to emulate/simulate a click on a button or a shortcut which apps such as Tasker can do. For instance, Google Assistant cannot be opened programatically (see How to start Google Assistant programatically?) due to permission denail. However, it can be opened by clicking on a shortcut on the screen opened according to the following instructions: https://www.ytechb.com/how-to-get-google-assistant-on-any-android-lollipop-device-without-root/
With Tasker I can then add an action which opens this shortcut. Now I am wondering how Tasker does this programatically.
You can launch another android app by using an Intent. To get the launch intent for another application you can use the
Context.getPackageManager().getLaunchIntentForPackage(String packagename);
If this is not null, then the app is installed on the device and you can launch it. If you want to get a list of other apps on the device you can use
Context.getPackageManager().queryIntentActivities(Intent intent, int flags);
You can find more information of these by looking at the PackageManager Docs
Related
My security company's mobile app (CPI inTouch) allows me to create "scenes" which trigger multiple actions at the same time with a press of one button (e.g. disarming the alarm and unlocking the smart lock on my door). I've also added shortcuts to each of the scenes on my home screen (on my Samsung Galaxy Note9, if that's relevant) so I can launch a scene via the shortcut without having to go into the app itself.
However, having just purchased Tasker, I'd like to trigger the shortcut (or the activity in the app itself) programmatically in a Tasker profile or some other automation app. I've tried plenty of apps that allow you to trigger a shortcut based on an event, but none have these particular shortcuts in the list of available ones. I read that I should be able to use a Send Intent task in Tasker to do this, but I don't know what the intent string would be or where to find it.
In case you can suggest a different way to achieve this, the main use case so far is to have my alarm system automatically disarmed when my phone's morning alarm goes off.
First thing to check would be...
create new task to Launch App,
find your CPI app and if it has a "+" in top right corner of app icon you can long press it to reveal a list of activities.
if your app does not offer those options...
The Tasker dev also has a group of plugins under the AutoApps group, there is one called AutoShortcut that launches shortcuts.
edit: there are apps such as APK Analyzer that can show you the activities and services inside an app and whether or not they can receive intents from external apps.
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
Does anyone know how to launch a 3rd party app in 'Kiosk Mode' i.e. to disable the System Bars, Home button, Back button etc while the app is running?
I'm writing an app from which the user can launch Skype to make a video call.
I want both my app and Skype to run in Kiosk Mode.
I have managed to get my app running in Kiosk Mode, but I can't work out how to control the system buttons when Skype is running.
Within my app, I achieve it by doing things like setting my app as the Home app, overriding 'OnWindowFocusChange' etc. There are a lot of articles on the web about how to do this kind of thing, but they all seem to be based on the assumption it's your own app you want to 'kiosk'
For what it's worth, I launch Skype with:
Uri uri = Uri.parse("skype:echo123?call&video=true");
Intent intent = new Intent("android.intent.action.VIEW", uri);
startActivity(intent);
I know it's possible to kiosk external applications because SureLock does it.
Any thoughts greatly appreciated.
Thanks
Damian.
So I'm building a custom launcher, I figured out how to replace the default android launcher with my launcher already from another question and have it working so that when the user presses home or back it always brings them back to my launcher.
Now I just need to allow the user to launch the other apps they have installed on their device from my app. Is there any easy way to get a page of app icons that are installed and allow the user to launch them? I'm just not really sure how to do this or where to start?
Any help would be great!
You should be able to get the installed applications from PackageManager:
public abstract List<ApplicationInfo> getInstalledApplications (int flags)
I found this question regarding launching an application: Android - Starting an application from an ApplicationInfo instance.
An snippet from the answer of that question:
You should be able to use getLaunchIntentForPackage() on PackageManager to get an Intent that meets your needs (or null if there is no such Intent).
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.