I am trying to collect the starting time of different apps, that is the time when the user tab some app's icon.
I guess there may be an intent was sent to respond this event, if so, how to catch this intent, so I would know an app was just starting, and record the current time?
I guess there may be an intent was sent to respond this event
No, sorry. startActivity() only uses an Intent with the starting activity (and perhaps a chooser). There is no broadcast Intent regarding the start of an activity.
I am trying to collect the starting time of different apps, that is the time when the user tab some app's icon.
That is not really possible.
A classic workaround for this was to keep tabs on LogCat. This technique has been blocked as of Android 4.2.
Beyond that, you are welcome to try polling ActivityManager or some script-kiddie solution like that, if you don't mind blowing a lot of battery and don't need good accuracy.
Related
Simple put: I want the app to relaunch (yes, from the launch activity, like if the user just tapped the icon button) every time Android kills my task because of lacking resources reasons.
The reason is that instead of managing everything that could possible go wrong after the app came back "from the dead", like NPEs, I want to start all over from the beginning.
I've searched for a "good practice" solution, but nothing came across.
Any ideas?
EDIT: I don't want to force the app back to foreground. However, if the user do it, I mean he brings it back to fore by his own free will, if Android killed my app because of resources purposes, I want the app to relaunch.
Sorry for not being clear previously.
Bringing your app to the foreground when it hasn't been explicitly opened by the user is considered a bad practice and discouraged. In fact, it won't be allowed in Android Q, except in a few cases:
Android Q places restrictions on when apps can start activities. This
behavior change helps minimize interruptions for the user and keeps
the user more in control of what's shown on their screen. In
particular, apps running on Android Q can start activities only when
one or more of the following conditions are met:
The app has a visible window, such as an activity in the foreground.
A different app that's in the foreground sends a PendingIntent belonging to the app. Examples include a Custom Tabs provider sending
a menu item pending intent.
The system sends a PendingIntent that belongs to the app, such as tapping on a notification. Only pending intents where the app is
expected to launch a UI are exempt.
The system sends a broadcast, such as SECRET_CODE_ACTION, to the app. Only specific broadcasts where the app is expected the launch a
UI are exempt.
Therefore, I would definitely recommend you to discard the idea.
I have an app that keeps the screen off when calling via bluetooth. It's a long story but for more context please visit http://www.rejh.nl/callscreenoff (not trying to spam, it's just to avoid the "why would you build an app for that?!" question)
Anyway. I have a problem. Everything works fine except that my Moto X turns on the screen a couple of (variable) seconds AFTER I hang up which makes it hard to determine if my app should lock the device (it could be the user who, after the call, immediately pulls his phone out of his pocket and wants to unlock it).
What I'm looking for is a way to detect which app caused the screen to turn on. Since I'm using a broadcastreceiver to detect USER_PRESENT and SCREEN_ON it would be nice if I could get this info in the receiver. Is there some data in the intent I receive about way I can find out which app caused the intent to fire screen to wake up?
Thanks in advance!
According to this answer it is not possible. The intent sender could put extras in the intent, which would give away the indentity of him, so your best bet would be either catching the intent in the debugger and inspecting the extras, or using an app for that, for example: Android Intent Intercept
I know the android broadcasts an Intent to start an activity. I can use a Broadcast Receiver to receive that intent. But what is the actual way of receiving an intent if an app starts in Android as I don't know what can be the actual intent for an app be (Means I can get the list of installed android applications but how to know what intent will be broadcasted if a particular app starts) .
EDIT :
I'm just adding this as a feature in my phone that if a game launches, then the Immersive mode will automatically be opened. I've system priveleges as well (as I can make the changes in SystemUI or frameworks as well). I don't want to touch the Launcher though.
by this way . But it's still a little bit weird as solution . I don't think there's any simple way to do it...
I need to know when a certain intent (in my case ACTION_CALL and ACTION_CALL_PRIVILEGED which are called when the user or an app make a phone call) was sent without registering my activity to handle it.
I don't want to interfere with the normal handling of that intent, i.e. the activity that's supposed to handle it should still handle it the usual manner (in my case the OutgoingCallBroadcaster).
I read here a suggestion to drop the ACTION_CALL_PRIVILEGED intent and issue another one, but want to avoid it. Moreover, I don't want to use an activity for the ACTION_CALL and issue another since it will appear in the intent chooser as an option and I want it to be transparent to the user and to always work.
Also working with the ActivityManager object like this suggestion is not recommended for core logic as stated in the documentation of the getRecentTasks method.
Please tell me if this is possible in Android, and if so how.
Thanks,
Amitai
No. This isn't possible. If it were possible it would allow me to write an app that monitors a user's behaviour without him knowing it. ACTION_CALL is an Intent to launch an Activity. You can, of course, intercept this, but that is clearly not what you want to do.
There are broadcast Intents that are sent out during the "call" process. You can monitor these, but you'll have to register to listen for them. Since you indicated that you don't want to register any listeners you are pretty much out of luck.
Which is a good thing, because otherwise people would be able to write a "NastyWare" application.
I am not satisfied with any of the app locker programs for Android that I have found and would like to create my own, but I am having trouble figuring out how to implement the actual lock. How does one go about implementing an app locker for Android?
There are two issues:
Detecting an Intent, usually from the launcher calling startActivity() or from an ad launching the market app (I'm not talking about broadcast intents -- I need to handle explicit Activity Intents).
The permissions for the locker apps I have seen all have "read system log files" and/or "retrieve running applications" which suggests they might use polling to look for app launches. I think I could do this, but I would like to find a better solution if possible.
Preventing the locked app from processing the Intent. I would prefer not to allow the locked app to run at all until the passcode is entered since it is impossible to tell what it might do when it starts up.
When running my current app locker, logcat shows "ActivityManager: Starting activity" first with the Intent for the locked app, then again with the Intent for the app locker, with nothing in between (separated by 10-20ms). If I enter the correct passcode then I see "ActivityManager: moveTaskToBack".
I have experimented with a test app which demonstrates that, using my current app locker, none of the Activity callbacks are invoked if the app is locked and I do not enter the correct passcode. So it appears to be preventing the app from starting (but I don't know how).
I could use ActivityManager.killBackgroundProcesses() to stop an app, but I have no guarantee that the app hasn't already started running by the time it gets "killed".
I might be able to use PackageManager.setApplicationEnabledSetting() to prevent an app from being instantiated, but I don't think that will take care of apps that are already running (which shouldn't be allowed to process new Intents or come to the foreground). I might be able to use killBackgroundProcesses() to stop all running locked processes so they would have to be re-instantiated. But I don't like this approach because other apps could mess with the Enabled settings and defeat the lock.
Optimally, the system would send every Intent to my app for inspection and allow me to stop or let it pass through, but I'm pretty sure that's not possible (at least, not for explicit intents to start activities from a launcher).
Does anyone know how app locker apps are implemented, or have any bright ideas on how it could be done?
I would look into the lifecycle. Once the app in question begins to load, some activity from that package will be added to the forefront activity.
A scan of the changes in forefront activities might do the trick.
http://developer.android.com/reference/android/app/Activity.html#ProcessLifecycle