views:

260

answers:

5

Hi I'm trying to develop an app that prevents a user from getting to a specified app without a password. The scenario is...

  1. user clicks on "Email" app (for example)
  2. my app detects launch of an app
  3. my app confirms it is the "Email" app
  4. my app opens a view over the top, asking for a password
  5. user enters a password, if correct, my app disappears, leaving the "Email" app on top

I'm ok doing the rest of it, just part 2 is puzzling me, and after many days reading up on Broadcast Intents etc and trying to listen for "android.intent.action.MAIN" etc in my trial projects I can't seem to detect when an app other than mine is started.

Can anyone help? Am I going about it the right way, in looking for new apps broadcasting an intent to start, or should I be reading the system log for new intents, or doing something in native code?

Any pointers would help, even if you can't answer it fully I'll be able to do some more research. Thanks a lot. Ian

+1  A: 

The main issue is you are trying to listen for implicit intents when the Launcher (home screen) is typically using explicit intents.

An implicit intent is when you want to say "Somebody play this video" and Android picks an app that can handle that intent.

An explicit intent is what happens when you click the "Email" icon on the home screen. It is specifically telling Android to open that specific app by fully qualified name (i.e. com.android.mail or something).

There is no way AFAIK to intercept such explicit intents. It is a security measure built into Android that no two Activities can have the same fully qualified package name. This prevents a third party from cloning the app and masquerading as that app. If what you wish to do was possible, you could theoretically install an app that could block all of your competition's apps from working.

What you are trying to do goes against the Android security model.

One thing you could do is partner with specific app developers to forward the intents to your security system, but that's probably not something you want to deal with.

CodeFusionMobile
A: 

Perhaps you need a service, something that will run in the background constantly. Than have your service do what you said. Listen for the android.intent.action.MAIN also with the category android.intent.category.LAUNCHER. Then have that broadcast receiver override the onReceive method and do check to see the name of the application etc.

Enigma Development
This sounds like just the method I was thinking about, but i'm struggling to receive the MAIN (cat. LAUNCHER) broadcast with a basic BroadcastReceiver.Has anyone managed to do this before?At this stage i'm just looking to detect that an application has been launched or resumed. I can then compare the package name to a string holding the name(s) i'm looking for.
Ian
+4  A: 

I think and hope this is not possible. Consider how easily such functionality could be abused by malicious software. You can listen to intents directed at you, and those that are broadcast, but application launching should not be a broadcast event.

What you may be able to do is replace the launcher. If the user agrees to it.

Pontus Gagge
+1 for a work-around to solve the real question.
Nate Bross
A: 

I'm not sure how they've done it, but apps like App Protector does exactly what you're asking for, so it is indeed technically possible.

hpe
Thanks for that, yes I've spotted there are a couple available, which is why I know it can be done. Looking at the requirements, they seem to access the eventlog so I wonder if they're detecting new entries in the log to determine if an app was started.What i'm trying to do is a bit different to what App Protector and App Lock do, but this whole app start detection part forms the basis of my idea. Any other pointers appreciated
Ian
A: 

Hi, i am looking out for the same, did anyone find a way to perform the above?

suppi
No I haven't yet. As hpe mentioned it can be done because of apps like App Protector and App Lock. I'd still be interested to know if anyone has an idea
Ian