I am trying to get the current running tasks on two devices with Android 5.0 and 7.0.
I used this code:
mActivityManager =(ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
if(Build.VERSION.SDK_INT > 20){
mCurrentPackageName = mActivityManager.getRunningAppProcesses().get(0).processName;
}
else{
mCurrentPackageName = mActivityManager.getRunningTasks(1).get(0).topActivity.getPackageName();
}
The problem is that I get my application package but when I launch another application I get :
com.sec.android.app.launcher
I wonder why this happens because on Android 4.4 it works right.
Check this answer:
Android 5.1.1 and above - getRunningAppProcesses() returns my application package only
This code works for me:
if (Build.VERSION.SDK_INT < 22) {
runningAppProcesses = ((ActivityManager) getSystemService(ACTIVITY_SERVICE)).getRunningAppProcesses();
} else runningAppProcesses = ProcessManager.getRunningAppProcessInfo(this);
Related
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 want to find GPU Vendor, its version and renderer.
I have used this code:-
renderer = GLES10.glGetString(GL10.GL_RENDERER);
vendor = GLES10.glGetString(GL10.GL_VENDOR);
version = GLES10.glGetString(GL10.GL_VERSION);
works on Android 4.3 and above, but when I ran this code on Android 2.3.6 it returns null.
However, the check following code check the GPUVersion which is returning "2.0" with 2.3.6:-
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
GPUVersion = configurationInfo.getGlEsVersion();
but still the above 3 lines returns null.
Is there any way to get the above information for all the devices.
Sometimes the only way to get a value across different Android versions is to split methods depending on which version you are running. You can do something like:
public static String getGlVersion(Context ctx) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
ActivityManager am = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
ConfigurationInfo configurationInfo = am.getDeviceConfigurationInfo();
return configurationInfo.getGlEsVersion();
} else {
return GLES10.glGetString(GLES10.GL_VERSION);
}
}
Be aware, though, that this might not work for all versions and you might need to split the method into more cases or change the min SDK_INT used for the comparison (I suspect for example that for Honeycomb it already needs the first method, but have not tested it).
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'm trying to find some info about apps I find using shell's top command. All I have is a process name (containing package name). Icon and app name would be perfect. I can't find any suitable soultion via google. Any help would be aprreciated;)
To be preemptive, I use top because it's the only way I found to show current processor usage. If someone's familiar with some more API friendly soultion, I'd be grateful.
Example process names I get are:
com.android.deskclock for desktop clock
com.creativemobile.DragRacing for game Drag Racing
Here how you get details. Since you have the package name, you can use it to get the corresponding application name, version, and icon.
List<PackageInfo> packagess = getPackageManager().getInstalledPackages(0);
for(int i=0;i<packagess.size();i++) {
PackageInfo pack = packagess.get(i);
if ((!getSysPackages) && (pack.versionName == null)) {
continue ;
}
//this is the application name
pack.applicationInfo.loadLabel(getPackageManager()).toString();
//this is the package name
pack.packageName;
//this is the version name
pack.versionName;
//this is the version code
pack.versionCode;
//this is the application icon
pack.applicationInfo.loadIcon(getPackageManager());
}
You can try out below code :
private String getTopActivity() {
ActivityManager mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> RunningTask = mActivityManager.getRunningTasks(1);
ActivityManager.RunningTaskInfo ar = RunningTask.get(30);
return ar.topActivity.getClassName().toString();
}
you have to give the permission of get task in the AndroidManifest.xml