Search in sources :

Example 41 with ActivityManager

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;
}
Also used : UriPermission(android.content.UriPermission) ActivityManager(android.app.ActivityManager) Uri(android.net.Uri) ContentProviderClient(android.content.ContentProviderClient)

Example 42 with ActivityManager

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);
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) Intent(android.content.Intent) ActivityManager(android.app.ActivityManager) Point(android.graphics.Point)

Example 43 with ActivityManager

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;
}
Also used : RunningServiceInfo(android.app.ActivityManager.RunningServiceInfo) ActivityManager(android.app.ActivityManager)

Example 44 with ActivityManager

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;
}
Also used : RunningAppProcessInfo(android.app.ActivityManager.RunningAppProcessInfo) ActivityManager(android.app.ActivityManager)

Example 45 with ActivityManager

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;
}
Also used : ActivityManager(android.app.ActivityManager)

Aggregations

ActivityManager (android.app.ActivityManager)612 Intent (android.content.Intent)61 RunningAppProcessInfo (android.app.ActivityManager.RunningAppProcessInfo)55 PackageManager (android.content.pm.PackageManager)50 Context (android.content.Context)47 ComponentName (android.content.ComponentName)44 RunningServiceInfo (android.app.ActivityManager.RunningServiceInfo)36 ArrayList (java.util.ArrayList)31 View (android.view.View)29 IOException (java.io.IOException)29 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)27 SuppressLint (android.annotation.SuppressLint)26 ImageView (android.widget.ImageView)25 TextView (android.widget.TextView)25 IActivityManager (android.app.IActivityManager)19 Point (android.graphics.Point)19 RemoteException (android.os.RemoteException)19 MemoryInfo (android.app.ActivityManager.MemoryInfo)18 Bitmap (android.graphics.Bitmap)18 AdapterView (android.widget.AdapterView)18