I want to know when emergency dialer is on the screen. So, I use this code but it doesn't even detect emergency dialer( Android api 21 and above ). Can anyone tell me what do I do wrong?
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.AppTask> tasks = am.getAppTasks();
for(ActivityManager.AppTask task : tasks){
Log.i("Point",task.getTaskInfo().baseIntent.getComponent().getPackageName()+" api 21");
}
This code detects only my app.
06-12 17:23:02.172 29795-29795/? I/Point﹕ com.prjct3.amadey.myapplication3 api 21
Thanks.
Related
I am working on an app which needs the information of how many application running in background at the system,
I want to get number of them.
Any idea please ?
This Below lines give the list of Apps which are in background,
ActivityManager actvityManager = (ActivityManager)
this.getSystemService( ACTIVITY_SERVICE );
List<RunningAppProcessInfo> procInfos = actvityManager.getRunningAppProcesses();
procInfos.size() gives you number of apps
I use the following snippet to kill tasks , it works perfectly fine but it doesn't kill my own app. How do i make it kill my app as well?
// kill tasks
List<String> reservedPackages = new ArrayList<String>();
reservedPackages.add("system");
reservedPackages.add("com.android.launcher2");
reservedPackages.add("com.android.inputmethod.latin");
reservedPackages.add("com.android.phone");
reservedPackages.add("com.android.wallpaper");
reservedPackages.add("com.google.process.gapps");
reservedPackages.add("android.process.acore");
reservedPackages.add("android.process.media");
ActivityManager am = (ActivityManager) context
.getSystemService(Activity.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> listeProcessus = am
.getRunningAppProcesses();
for (RunningAppProcessInfo processus : listeProcessus) {
String packageName = processus.processName.split(":")[0];
if (!context.getPackageName().equals(packageName)
&& !reservedPackages.contains(packageName)) {
am.restartPackage(packageName);
}
}
Google has recently removed the GET_TASKS permission and developers can't make changes to running tasks . The only remained way is to have a root access and close the running tasks that is not possible for All Android Users
As of api 21 (android lolipop) it has been removed by Google
I use the the below code to get the name of the application that is on the top.but on Android 5.0, it always give the same name of the application having package name(com.google.android.googlequicksearchbox). below code does not give the name of the application that is on the top.
ActivityManager am = (ActivityManager) getApplicationContext()
.getSystemService(Context.ACTIVITY_SERVICE);
RunningTaskInfo taskInfo = am.getRunningTasks(1).get(0);
String packageName = taskInfo.topActivity.getPackageName();
On Android 5.0 how I can get the name of the application that is on the top?
Android 5.0 ActivityManager's getRunningTasks()
It has been deprecated from Android L. I don't think anyway to get it now.
I am trying to develop an application that detect launch of each application which are installed on device.I want to develop same scenario like this.
Accroding to it logcat supports only below 4.0(ICS) version and my requirement is for above ICS version.I have seen many application on play store likeSmart appLock.How to create this kind of application which supports all version of android from 2.2 onwards.
What I think is that you can keep track of the applications currently running:
final ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
final List<RunningTaskInfo> recentTasks = activityManager.getRunningTasks(Integer.MAX_VALUE);
for (int i = 0; i < recentTasks.size(); i++)
{
Log.d("Executed app", "Application executed : " +recentTasks.get(i).baseActivity.toShortString()+ "\t\t ID: "+recentTasks.get(i).id+"");
}
Once your polling yealds a new app entry into the list above, you get your desired result.
I am encountering a problem that i can't not solve for the moment.
The purpose of the code is to monitor which applications are running at current moment.
I used the following code and logged the resulting package name, it worked.
ActivityManager am = (ActivityManager) context.getSystemService(Activity.ACTIVITY_SERVICE);
String packageName = am.getRunningTasks(1).get(0).topActivity.getPackageName();
Log.i("TTWYMonitor", packageName);
But I use that code in a BroadcastReceiver, nothing happened.
In manifest,I declared an intent receiver android:name=".MonitorApplication.
What should I do, then?
Please give any suggestion.
Yahel : Thanks and sorry for my informal question.
replace the "Activity" in getSystemService's parameters with "Context":
ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
I tested it and works fine for me!