Launch my application when a user opens a certain application - Android - java

Is there a way to open my application when a user opens a certain application?
For instance, I want to launch my application's floating button as soon as the user opens Instagram. Or even better is they open the "story" camera?
This is different from inexplicit intent, since, I don't have a way of interacting with Instagram, but is it still possible?
Do I need to check with the system to see which application are currently open or is there another way of doing this?

As NomadMaker says, in general this is difficult to do because it would be a security issue. In fact, an issue like this was published as the Strandhogg vulnerability. That said, some apps (like LastPass) use/abuse the AccessibilityService API to get this information. This would be an OK way to do this if you're making an app for yourself, but is discouraged if you plan to distribute the app.

Related

Is it possible to know the app which is opened currently?

I am a beginner in android development. I want to know that is it possible to know the app which is opened currently. I came to know that finding the apps which are running currently through Activity Manager (getRunningTasks()) is now removed from the Android studio. So I want to know is there any other way to know? I just want to know the app which is opened and running currently on the mobile but not the apps running in the background Could somebody please help me in this case?
You can use AccessibilityService to get event notification. But AccessibilityService are specifically for accessibility uses. If you use the service for other purposes, then the application will more likely to be downed/removed for PlayStore due to policies. Another viable option is UsageStatsManager, but with some limitations.
UsageStatsManager is not push event based system. You have to poll in few mills(depends upon the use-case)
Usage Access Permission grant/deny is not straight forward. You have to start Setting Activity with Settings#ACTION_USAGE_ACCESS_SETTINGS action and have to rely on the users understanding of how to grant permission(Since permission list may contain other applications).

How to add shortcut on home screen when app gets install

I know it's not the best practice, but it is a requested feature (e.g. for business apps). When the App gets installed, I need to automatically place it on the home screen. I saw a lot of code on the internet, but all of the code only works on button click when the app starts. But I need to place a shortcut on the homescreen immediately after the app is installed and before the app starts. Is there a way I can achieve this?
PS: To make the question more clear: The app will be distributed without Google Play Store, so that's not an option.
Thanks for your help!
Best regards,
Robin
You can't run any code in your application before the user starts your application for first time during to restrictions since Android 3.1. Check this for more information
That's an optional feature of the Market app, not of the apps themselves. When designing an application , it does not receive a broadcast about itself being installed.
the first time the app launched can create it.
You can achieve that by creating a method in your main activity and call this method from oncreate and create a boolean variable andsave it in shared preferences

Get State of Toggle Button in Another Running Android App

I am writing an App (MyApp) in Tasker that would need to read the State of a Toggle Button in another App (AppB) that I haven't written. It's for reporting purposes. I am a seasoned programmer, but are new to Android. Please bear that in mind:-)
Tasker have support for Java code, and have access to the full SDK of my Android 4.3 Phone.
The app will run on Android 4.3+.
I am already using AutoInput that is perfectly capable of getting the ID of widgets (Buttons etc) in other Apps, and AutoInput is also capable of Pressing these Buttons (AutoInput Accessibility must be turned ON). AutoInput will have support for what I am asking later, but I badly need it now!
So the question is:
How can MyApp get the State of a Toggle Button (with ID "toggle") in AppB using Java?
I am afraid this will not be possible by easy means. The applications in Android are isolated and cannot ask for others' applications controls due to the security policy. Without the access to the AppB code and possibility to change it this will not be possible.
The AppB would have to share the state of the toggle to your app: either via content provider or simple intent each time the toggle is changed. This requires changes in AppB code which I assume is not possible in your case. I see no other way to get around this.
I am writing an App (MyApp) in Tasker that would need to read the
State of a Toggle Button in another App (AppB) that I haven't
written
In Android, by default each of the application runs in its own process and each app is Sand-Boxed.
Therefore, you cannot read the data from other application until it is shared explicitly by the particular application.

Can I monitor when an app has been closed? For example when a user closes Maps(or any other app) can I make a popup come up saying "you closed maps"

I basically want to add a feature to an app I am making but it would require me to know when the user closes certain apps. For example if the user closes any of the following; Maps, Firefox, Facebook, and Camera, A yes/no notification, kinda specific to the app, would come up for the user to answer.
It's something that sounds complicated i know but im pretty sure I've seen it done on a few android apps before.
Thanks
edit: so i was thinking since tasker can perform a task upon opening an app and then stopping the task when closing the app i can do what i want right?
The closest option available for monitoring the status of other applications and packages is through the use of a BroadcastReceiver registered to listen for Intents related to packages or applications. I looked through the intents available (the actions are constants with names starting with ACTION_), and none were directly related to another application closing, however you may be able to capture something, such as a changed battery status, that can look at the status of running applications in question.

Possible to 'layer' Android applications?

I know this in general is beyond the scope of SO, but I am looking for some basic yes/no info to see if it is even feasible to proceed... I am thinking about building and Android 'note-taking/annotation' app that runs 'over' other installed Android apps, such as the web browser for example.
Essentially, while the user is browsing, my app would be running in the bg as a service, and then they could activate it which would then essentially intercept user inputs and translate those on a transparent canvas over the web browser into lines, shapes, etc. The user could then take a screen-cap of their marking with the underlying web page, which would be stored to the sd card.
This is a very good idea and a great question, but sadly, I do not believe it is possible.
The way Android is designed only one Activity can have focus at a time, while a Service could run in the background, the user would not be able to interact with it. The user can only interact with the currently active Activity.
Again, love the idea, but it is sadly not supported.
You might be able to achieve this with the WindowManager service. You can then use that to call addView() with a view of type TYPE_SYSTEM_ALERT, or possibly TYPE_SYSTEM_OVERLAY (but see the notes in the documentation about taking input focus).
I haven't tried it myself, but I've seen several apps (often dictionary apps that translate whatever words you tap on) that do overlays, and they always seem to require the SYSTEM_ALERT_WINDOW permission.

Categories

Resources