application open and close notification - android

How can I receive a notification whenever a user is opening and closing any application on the phone?

Depends on what you want. Inside the application: ofcourse. you can find out if your own application is getting opened or closed using the function from the lifecycle.
Using the same functions you can deduce you are being send to the background, so that's a bit like finding out something is happening, although it doesn't need to be another app (it could just be 'home'). Also, you won't get the notice what app is being run.
As far as I know there is no "this application is being started" trigger, but you could go the long way around: just like taskkillers do, you can ofcourse find out what tasks are being run. If one is added, then you can kind-off be sure it is being started, and so there you could create some sort of trigger for yourself. But this sounds a bit like a hack.
Maybe you want to expand on your goal, and check out of there are other sollutions?

Related

how to get the event of app instance clearing in android

in my app I am using push notifications to notify the user about something.Based on different app state I have to assign different activities to click event of notification. If the user press home button and app is in background i have to handle that scenario as well. But here the issue come when user clear the app instance from memory. If user do that I have to consider it as app closed. But i dont know how to get that app instance clear event. Please help me.
The task you are willing to solve is equivalent to protection against the task manager. I am not sure that your app knows better than the user whether or not to show the ads. Please do not create malware.
Try the UncaughtExceptionHandler stuff like setUncaughtExceptionHandler(). I am not sure it will be necessarily called, and it may depend on the Android version, but it is something to start with.
Another possibility is to use one or more remote service(s). The processes will not die all at once, there's a good chance that one process may notice the death of another process. There should be some kind of wait-for-process-to-complete at least on the JNI level.
One more possibility is to use two applications, one monitoring the other...
After you solve this problem, please post your own answer telling the world what you did.

Android: application startup time

I want to know the average start-up time of all the apps on android device. And this is supposed to be done by my app. So, is it possible to get such information from the app level programatically?
I assume you mean the time it takes for a given app to complete its onCreate() method. You might be able to do something on a rooted phone with extending onCreate() with a timer that logs to somewhere for your app.
This isn't going to work. You would have to start an app and time it, but you do not have access to the information about when another app has finished loading. Furthermore,.. how do you define start-up time? The time taken until the app opens or the time until past the loading screen.. or the time until past the splash screen...?
The way I am trying to solve this problem is by using a service to monitor the logs that will start a timer when app X is started. We have that working properly. The problem we are having is how to define the app as done loading. Once we have that we can gather data. But I am still looking for a way to know when app X moves from the onCreate() method from one activity to the onCreate() method of another. This will obviously only work for apps that have a loading activity for their app.
Effectively, this a really hard problem to both define and solve. If you ever come up with anything different than what I have, I'd love to hear it.

How to trigger a status bar notification without starting the actual view in android?

I am new to android development and I did research on notifications using toast and status bar notification.
And I also managed to execute the code properly to make a notification work!!!
The problem is there are only methods like triggering a notification by clicking a button is available. Other wise I managed to directly call the codes within the method that is called by the button, to make it trigger automatically. But the problem is the view of the corresponding screen is showing up a tleast for a sec and then closing while this notification is triggered.
So how can i write a code that just triggers the notification without popping up the screen even for a second.
I need a result like the way the new SMS alert works...And I did a lot of research on this and all I got was about basic notification. So please help as I am new to this!!!
Using a Service would be the "right" way to do it - and if this is a professional app you are writing, then that's the way to go.
Bear in mind you still need some activities in your application, in order to trigger the service.
If you are just experimenting, then maybe what you need is a cheap hack...
Here's the cheap and nasty way to get your proof-of-concept done:
either - create a transparent Activity so that nothing is displayed when the activity code gets called.
or - create your notification from within the Activity.onCreate() method, and then call finish() at the end of that method. Your activity will never get shown to the user.
To me, it looks like you are just experimenting, and a transparent activity might get you further faster... ymmv
Legendary you need service and handler. Using service you can get data. and using handler you can modify the UI of your app.
here you can get more information on it.
http://developer.android.com/training/notify-user/display-progress.html
Working with handlers and threads in service, Thread.sleep makes the program to hang?

Call Back button from service Android (system-wide)

I need to remap the Honeycomb "Back" button to a button in my app (service) but after hours of search I'm still nowhere. The functionality must be there system-wise like the back button in ButtonSaviour (see market)
Most solutions for emulating the Back button are based on calling finish(). Not sure if it will work in my case since I have to call finish() from whatever activity I find on the foreground. I do manage to get the foreground application with the code
ActivityManager am = (ActivityManager) getContext().getSystemService(getContext().ACTIVITY_SERVICE);
List<RunningTaskInfo> T = am.getRunningTasks(5);
System.out.println("top activity: "+T.get(0).topActivity);
but I'm not sure how I should send a finish() intent to that..
I also tried the solution posted here http://www.anddev.org/throwing-simulating_keystrokes_programatically-t717.html but I couldn't get around the IWindowManager (has it been removed in Honeycomb?). That solution, however, looks interesting because with that I could send KeyEvent.KEYCODE_BACK from anywhere, anytime.
Please let me know which is the best way to implement this functionality SYSTEM-WIDE, i.e. from a service rather than from a specific application of mine.
cheers
PS: The app is meant to run on my own rooted tablet rather than for distribution to others.
Why does people spam the thread with advises about designs and good practices when the question clearly states that this will not be used for the market?!
Replacing android nav bar is sometimes required in some applications, even if no more than for own pleasure (or programmer satisfaction).
try from java Runtime exec
input keyevent 4
4 means back
button savior most likely uses hidden api, I had encountered that somewere, but don't remember now. When I will find it, I will post back.
The reason you're not finding an answer to this is that this is a terribly hacky way to do things and it indicates that there is something majorly broken with the design of your app. You should not be able to "call the back button," that doesn't make any sense at all. In fact, you really shouldn't change the behavior of the back button at all, users get really upset when you do that. If you have a service, and you need to send messages to an Activity, then use a messenger. But you should certainly not (and certainly cannot) be changing the behavior of other apps from your service. (This would indicate a major security flaw in the system, and would let you hijack someone else's UI, doing potentially dangerous, or at least annoying, things.)
Will the activity be open when you want to simulate the back button? If so, you could set up a timer inside your activity that checks for an exit file every 5 seconds or so. Then, from your service, create the exit file when you want to simulate the back press. When the activity sees that the exit file was created, delete that file and call finish().
As others have suggested, though, doing things this way means that you might need to rethink the app's design. What exactly are you trying to achieve?

android apps that alter normal phone operations

so i was wondering if its possible to for an application that i would write to be constantly running in the background and alter regular phone operations. For example this could be something like as soon as you receive a text from anyone you forward it automatically to another number. Is something like this at all possible?
Just to be clear I don't want to solve that particular problem through some other means, just want to know if apps can accomplish that.
Also if that is possible is it possible for an app that i write to alter more immediate and instant things, like an incoming call.
thanks all for reading this, and hopefully a helpful response :)
It depends on how far you want to go, but I would expect that what you want to achieve probably isn't possible.
The Android OS does reserve some actions and prevent them from being doing programmatically. For example, you can display the Dialer with a number filled in but the user has to press the call button to make a call. Similarly, you can display the SMS app with a message already written but it is up to the user to send the message.
I don't know for sure, but I assume this is for security. For example, let's imagine you could write an application which could start a call with no user interaction. I would release my Super-Handy-Dialer application which makes quick calls for you making you life easier, but what it also would do is wait until 2am and call my premium rate phone line every night for 3 hours.

Categories

Resources