Issue
I'm trying to develop an app that prevents a user from getting to a specified app without a password. The scenario is...
- user clicks on "Email" app (for example)
- my app detects launch of an app
- my app confirms it is the "Email" app
- my app opens a view over the top, asking for a password
- 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
Solution
I think we can use logcat
and analyze it's output.
In all similar programs I have found this permission :
android.permission.READ_LOGS
It means all of them use it but it seems the program starts and after that our program (app protector) will start and bring front.
Use below code :
try
{
Process mLogcatProc = null;
BufferedReader reader = null;
mLogcatProc = Runtime.getRuntime().exec(new String[]{"logcat", "-d"});
reader = new BufferedReader(new InputStreamReader(mLogcatProc.getInputStream()));
String line;
final StringBuilder log = new StringBuilder();
String separator = System.getProperty("line.separator");
while ((line = reader.readLine()) != null)
{
log.append(line);
log.append(separator);
}
String w = log.toString();
Toast.makeText(getApplicationContext(),w, Toast.LENGTH_LONG).show();
}
catch (Exception e)
{
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
And do not forget to add it's permission in Manifest file.
Answered By - M.Movaffagh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.