Listening to Intent being sent - android

I'm currently working on a productivity app. One of the features includes obtaining an information about apps that are started by the user
For example I would like to obtain information that the user has started the Youtube app or listen for a specific Intent being sent without registrating a BroadcastReceiver
Is this even possible?

You cannot intercept intents sent to other apps by extending the BroadcastReceiver abstract class for obvious security reasons. So, basically, this is not allowed using conventional features (or APIs) of the Android SDK. There might be some hacks out there that could work, but they're all hacks at the end of the day which are not guaranteed to work, for example there are some articles proposing to read the system's log, it used to work in older api levels but not anymore...see some references below and make sure you read the comments as well...
Android, Detect when other apps are launched
Detect when user launches a new application on an Android device
In simple words, you can't do that. Note, that having root is a complete different story

Related

How to detect if another application is open in Flutter?

[EDITED]
I want to create an application that discourages the usage of social media applications. Like if they open Instagram or something then the Flutter app will know.
How would I detect if another application (Such as Instagram or Twitter) is open when my Flutter app is opened?
If this is difficult to implement in Flutter, can anyone suggest some other languages or code for this functionality?
Thanks!!
It is possible at least on Android. I do not program for IOS so I can't say for sure. As #Gaurav pointed out, the solution will need to be custom-made and it probably won't be specific to Flutter. If you are willing to work outside Flutter than it is possible.
Once again, the following solutions are for Android devices:
Solution 1: Since you are targeting social media apps you can lookup the public intents of each app (i.e. Facebook, WhatsApp, etc...) find out the names of the intents they are broadcasting and add a broadcast receiver in your application. Many will say this is not a good idea because the app developer's themselves could change the intents and that you shouldn't listen for anything that hasn't been declared for public use. They are probably right, but this discussion is about how to detect the other apps launching and this method works.
Simply google how to add a broadcast receiver, a good example can be found here.
There are websites that contain databases for a lot of broadcast intents for popular Android applications, but if you have trouble finding the name of a particular one then I'd suggest using ADB to find it. For example, Facebook would be:
adb shell pm dump com.facebook.katana | grep ' filter' | cut -d ' ' -f 12
In some versions of Android broadcast intents do not work, however registering it in the application has worked pretty well for myself.
Once you have a listener setup properly, then you can detect the app when the user launches it and process it accordingly.
Solution 2: You could monitor the processes on the Android device via "Process" and/or "PackageManager" and see when one of the social media applications popup. This method is not very reliable because apps are on all the time and just because they're in the process list doesn't mean they are actively being used.
Solution 3: Once again, this is a very "hacky" solution, but you could listen to the logs on each device. Basically get the output of console logs, read the last 100 lines and see if the app is doing something. If so, then you may be able to determine if the app is active. The biggest problem with this solution (besides trying to read logs on all your user's devices) is that this is not an instant solution and may require special privileges depending on the device you're working on. You would also probably need to setup a service that actively listens and reads the logs, which might cause some significant battery usage.

Can an android application get information from other applications?

I am new to android development. I came to know that Intent and Intent filters can be used to share data among applications but I wonder if it is possible to design an android application which can extract some specific information from other applications while running in the background. For example, if the user is using whatsapp it may get know the call drop rate or if a video is being played at user terminal in YouTube, Facebook or Netflix, it will get buffer playtime, video bitrate etc. I will be very grateful if answer to this question is provided with an example.
No, mostly no.
However, as wrote Tim Castelijns, if the 'target' app allows it, like via a content provider, its possible.
On a rooted device, after long hours of reverse engineering the targeted apps, it MAY also be possible to get some info. Only from rooted devices too.
Other case is you write several app and design that they can communicate together, like via intents, content providers.
There is also possible to get the list of running apps (user must permit it)
In Android, each application is running on its own "sandbox" that is supposed to be isolated from the rest of the applications running on the device.
In order for an application to communicate with other applications, the Android framework supplies several mechanisms to send/receive data to/from other applications: Intents, IPC (AIDL), Content Providers etc...
Each application that wants to expose its data to other applications on the device needs to implement an interface using one or more of the mechanisms described above.
That means that if an application doesn't implement an interface to expose its data or inner workings, it won't be possible for another application to access this information.
Keep in mind that some applications choose to save some of their data on publicly available disk spaces (i.e. a camera that takes pictures might save them on the SDcard that is accessible by all applications). In that case, if you know what to look for, you can tell certain things about certain applications.
In addition, the Android operation system exposes the states of several global settings such as: Device's connectivity state, Battery state, currently opened Bluetooth interfaces, running applications, last executed apps etc...
This configurations might give you an overall idea of what is happening on the device.
As indicated in other answers, you're mostly limited to what apps will explicitly make available to you; in fact, well-engineered apps will generally try to prevent "information leakage" beyond what they actually want to make available.
Some other people mentioned Content Providers but the one other construct to look into is Broadcasts. If an app broadcasts an intent locally (i.e. is using the Local Broadcast Manager) you won't be able to see it but if they're using a "system-wide" broadcast or receiving another "system-wide" broadcast you can receive the same event.

Android - Get event for Android Message application whenever opened

In Android, I want to know if I can receive the event whenever I open Android Message Application?
I tried get task in foreground but that didn't work in service as for that service has to continuously poll
Kindly guide
The only way you can achieve this is by polling. No other way :(
I can receive the event whenever I open Android Message Application?
No.
First, there are thousands of Android device models, spanning hundreds of manufacturers. There are dozens upon dozens of "Android Message Application" pre-installed across the device models, as manufacturers often provide their own. There are also hundreds of "Android Message Applications" available on the Play Store and elsewhere. You have no great way to know what apps are and are not "Android Messaging Applications", though you could try to examine <intent-filter> structures and deduce which ones might meet your requirements.
Second, there are no events posted to ordinary Android SDK apps when other apps or their activities start. Even some of the polling techniques that you mention will not work on Android 5.0+, and any that still do work represent bugs that should get fixed. Google is locking down this information for privacy and security reasons, such as to help prevent OAuth hijacking attacks like this one.

How to protect against automated scans and calls of non-exported activities

My company has some android apps on Google Play that are occasionally targeted by malicious automated tools that scan and launch all activities in the apps. (I was able to detect these scans because they generate a lot of crash reports.) What I find most worrisome about these scans is that they are able to make explicit intent calls to non-exported activities. That is, they are calling activities have the exported attribute set to false and don't have <intent-filter>s.
Are there any additional steps I can take to prevent non-exported activities from being invoked outside my app? Are there any other security measures that I should take?
One other interesting tidbit about these scans. They all seem to be run from an emulator. Perhaps they have some mechanism to make the intents look like they are coming from inside my app. If this is the case, is there some way I can protect against that?

Control over app activities in android

As far as I know, there is no way to control over the activities occurring in an app in android phones unless the application that you want to log/monitor is written by you.
I wonder is it really like that or is there any possible way to do this? For example, is it possible to control over emails which, let's say, who I sent an email to in an android phone?
It is not possible to "just log it". Some events are possible to catch in broadcast receivers in a logging application. The user will get notified by particular event sniffing when installing such an application, by approving the permissions request.
It's generally possible to add instrumentation for security purposes to apps where they interface to the sdk api's, either by modifying the platform (rooted phone) or by decompiling, modifying, and recompiling the app using apktool.
possible of course does not mean trivially easy.

Categories

Resources