I have done the coding on getting all the installed packages in the android system! now what I want is to get the pid of that package since I want the current resource usage of the package! I dont know the method of doing this, where I know the reverse of it! :) I dont want to use the shell either! is there a way to achieve this! or else I'll state what I want to do and suggest me a better way..
what I want :
I have created an activity, where I take all the current installed third party applications or the system. used the package manager to get it! I listed it on a layout and when I click on an application I want it to direct to another screen where all the details are shown about the application. I already have some details which i got using the package name of the application. the thing is, I want to show the memory info, and the code size of the application! how can I achieve this! :)
please help!
PID is denoted to Process ID in Android. And as you are telling you need process ID of all installed applications, But afaik PID is given to application/service/process which are running, So you can not ask for process ID for all installed apps.
You can get pids of all running apps, by using below code..
RunningAppProcessInfo service[]= manager.getRunningAppProcesses();
String = service.pid;
Related
How to check if intent or app has started ?
My use case is I am showing up notifications through my app and I want to clear them all via myBuilder.cancelAll() if default messaging app has started since my app shows sms notifications. So I am kind of looking for something like:
if (smsAppStarted) {
myBuilder.cancelAll();
}
Thanks
To check if an app has started:
Get the package name of the sms app you want to check.
Then refer to my answer here:
Android how to know an app has been started and range apps priority according the starting times
By using that code, the list taskInfo will contain the list of all apps currently running. Search that list using the package name of the sms app. If it is present in that list, it means that that app has started and currently running.
If I get you right, you need to determine, if another app is currently running. If so, then use this solution.
I want to implement an app which can detect what app launched, to do something with that!
for example I have a list of installed applications in my app and mark one favorite app. and when I start that marked app from default launcher or anyway, I could detect it and do something with that by a background service or broadcast receiver(For example launch a toast message).
How can I do this?
this isnt possible.. to be able to monitor all intents would make android extremely insecure
http://groups.google.com/group/andro...ddc9d36a24d77b
but there are ways to know when an application is launched. you just have to be creative.
this will give you a list of all the applications running.
Code:
ActivityManager am = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> runningAppProcessInfo = am.getRunningAppProcesses();
however to know when an app is launched you would need a timed loop and then check between versions of the List to see if there is a new app. this would suck the juice and be inneficient
AppProtector seem to access the eventlog. maybe you could have a ContentObserver attached to the event log
http://developer.android.com/referen.../EventLog.html
http://developer.android.com/referen...tObserver.html
EDIT
Interesting.
I also found this which solve your problem.
When you open any app from launcher below code will return the info of opened app so now you need to compare a package name with your favourite app package name which you already stored in your app database.
Code:
String str = ((ActivityManager.RunningTaskInfo)this.am.getRunningTasks(1).get(0)).topActivity.getPackageName();
I am trying to kill an application programatically as Android does when there is overload in memory.. I had searched many post in stackoverflow itself regarding killing of an application, all concluded by saying it is not possible by the user to do at a point of time but it can be done by following the standards like finishing a activity once it moved and at last call killProcess(pid) fn.
My doubt is killing an app is force stopping it and clearing the data it holds.. Is it possible to do these programattically? If so we can acheive killing process programatically..
Regards,
Deepak
yes you can do it with one line .
but you your device need to be rooted first
android.os.Process.killProcess(pid);
You can stop any other running application by it's name like this:
ActivityManager am = (ActivityManager) context.getSystemService(Activity.ACTIVITY_SERVICE);
am.killBackgroundProcesses(appPackageName);
This code will work in API8 or hier.
What do you mean by "clean data"? If you mean release memory that is used by currently running process - it will be done automatically.
I could get a solution to Clear the Application data programatically.. I could acheive it by Reflecting the method which is used to do clear data when we click the Clear Data button in the Settings->Application->Manage Application->App Name.. I had found that method from the android source..
Note:
The clear data fn only clears the data but not Force Stopping the app in 4.0+ , but the app is force stopping also while clearing the data in 2.3..
Thanks for the replies
What I want is: when there is an App start, my App can know it and do something about it.
I had look up the android API but can't resolve it.
Is there any way to make it possible?
Not really. The general philosophy of Android is that one app should not affect the behaviour of other apps unless it's a system app or a device administrator. And there are no APIs for this for device administrators, so you can't do anything about it. Unless, of course, you modify the platform.
What are you trying to do?
Please explain what do you mean by "do something"
However there is a topActivity field defined in the RunningTaskInfo class. You can get a list of running tasks via the getRunningTasks(int) method in the ActivityManager and can traverse through that list to find the currently active task by checking the topActivity field.
I have a requirement that , I want to do some changes in my application, If some other application ,let say "com.android.abc" is in use.
Pl. let me know can I get the package names of the currently running apps in my application..?
I can use Broad cast receiver , but I dont have access for the other application to modify it and send some notification to my app.
thanks.
See this.
If you can't do that (as in, get that permission), then you can't accomplish this.