use of android.app.ActivityManager in project android_frameworks_base by ResurrectionRemix.
the class OpenExternalDirectoryActivity method getIntentForExistingPermission.
private static Intent getIntentForExistingPermission(OpenExternalDirectoryActivity activity, boolean isRoot, File root, File file) {
final String packageName = activity.getCallingPackage();
final ContentProviderClient storageClient = activity.getExternalStorageClient();
final Uri grantedUri = getGrantedUriPermission(activity, storageClient, file);
final Uri rootUri = root.equals(file) ? grantedUri : getGrantedUriPermission(activity, storageClient, root);
if (DEBUG)
Log.d(TAG, "checking if " + packageName + " already has permission for " + grantedUri + " or its root (" + rootUri + ")");
final ActivityManager am = (ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE);
for (UriPermission uriPermission : am.getGrantedUriPermissions(packageName).getList()) {
final Uri uri = uriPermission.getUri();
if (uri == null) {
Log.w(TAG, "null URI for " + uriPermission);
continue;
}
if (uri.equals(grantedUri) || uri.equals(rootUri)) {
if (DEBUG)
Log.d(TAG, packageName + " already has permission: " + uriPermission);
return createGrantedUriPermissionsIntent(grantedUri);
}
}
if (DEBUG)
Log.d(TAG, packageName + " does not have permission for " + grantedUri);
return null;
}
use of android.app.ActivityManager in project android_frameworks_base by ResurrectionRemix.
the class PieControlPanel method toggleLastApp.
private void toggleLastApp() {
int lastAppId = 0;
int looper = 1;
String packageName;
final Intent intent = new Intent(Intent.ACTION_MAIN);
final ActivityManager am = (ActivityManager) mContext.getSystemService(Activity.ACTIVITY_SERVICE);
String defaultHomePackage = "com.android.launcher";
intent.addCategory(Intent.CATEGORY_HOME);
final ResolveInfo res = mContext.getPackageManager().resolveActivity(intent, 0);
if (res.activityInfo != null && !res.activityInfo.packageName.equals("android")) {
defaultHomePackage = res.activityInfo.packageName;
}
List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(5);
// Note, we'll only get as many as the system currently has - up to 5
while ((lastAppId == 0) && (looper < tasks.size())) {
packageName = tasks.get(looper).topActivity.getPackageName();
if (!packageName.equals(defaultHomePackage) && !packageName.equals("com.android.systemui")) {
lastAppId = tasks.get(looper).id;
}
looper++;
}
if (lastAppId != 0) {
am.moveTaskToFront(lastAppId, am.MOVE_TASK_NO_USER_ACTION);
}
}
use of android.app.ActivityManager in project AprilBeacon-Android-SDK by AprilBrother.
the class ServiceStatusUtils method isServiceRunning.
public static boolean isServiceRunning(Context context, String serviename) {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningServiceInfo> infos = am.getRunningServices(100);
for (RunningServiceInfo info : infos) {
String classname = info.service.getClassName();
if (serviename.equals(classname)) {
return true;
}
}
return false;
}
use of android.app.ActivityManager in project DroidPlugin by DroidPluginTeam.
the class PluginProcessManager method getCurrentProcessName.
public static String getCurrentProcessName(Context context) {
if (context == null)
return sCurrentProcessName;
synchronized (sGetCurrentProcessNameLock) {
if (sCurrentProcessName == null) {
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> infos = activityManager.getRunningAppProcesses();
if (infos == null)
return null;
for (RunningAppProcessInfo info : infos) {
if (info.pid == android.os.Process.myPid()) {
sCurrentProcessName = info.processName;
return sCurrentProcessName;
}
}
}
}
return sCurrentProcessName;
}
use of android.app.ActivityManager in project AndroidUtilCode by Blankj.
the class AppUtils method isAppForeground.
/**
* 判断App是否处于前台
*
* @param context 上下文
* @return {@code true}: 是<br>{@code false}: 否
*/
public static boolean isAppForeground(Context context) {
ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> infos = manager.getRunningAppProcesses();
if (infos == null || infos.size() == 0)
return false;
for (ActivityManager.RunningAppProcessInfo info : infos) {
if (info.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
return info.processName.equals(context.getPackageName());
}
}
return false;
}
Aggregations