Example usage for android.content Context ACTIVITY_SERVICE

List of usage examples for android.content Context ACTIVITY_SERVICE

Introduction

In this page you can find the example usage for android.content Context ACTIVITY_SERVICE.

Prototype

String ACTIVITY_SERVICE

To view the source code for android.content Context ACTIVITY_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.app.ActivityManager for interacting with the global system state.

Usage

From source file:com.silentcircle.contacts.list.ShortcutIntentBuilder.java

public ShortcutIntentBuilder(Context context, OnShortcutIntentCreatedListener listener) {
    mContext = context;/* w  w w .ja va2 s  . c  o  m*/
    mListener = listener;

    mResources = context.getResources();
    final ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    mIconSize = mResources.getDimensionPixelSize(R.dimen.shortcut_icon_size);
    if (mIconSize == 0) {
        mIconSize = am.getLauncherLargeIconSize();
    }
    mIconDensity = am.getLauncherLargeIconDensity();
    mOverlayTextBackgroundColor = ContextCompat.getColor(mContext, R.color.shortcut_overlay_text_background);
}

From source file:com.entropy.promoenginedemoapp.gcm.MyGcmListenerService.java

private boolean isApplicationSentToBackground(final Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> tasks = am.getRunningTasks(1);
    if (!tasks.isEmpty()) {
        ComponentName topActivity = tasks.get(0).topActivity;
        if (!topActivity.getPackageName().equals(context.getPackageName())) {
            return true;
        }//from w  w  w.  jav a2  s .  c o m
    }
    return false;
}

From source file:com.kratav.tinySurprise.notification.MyGcmListenerService.java

public boolean isRunning() {
    ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningTaskInfo> tasks = activityManager.getRunningTasks(Integer.MAX_VALUE);

    for (ActivityManager.RunningTaskInfo task : tasks) {
        if (getPackageName().equalsIgnoreCase(task.baseActivity.getPackageName()))
            return true;
    }/* w w w. ja  v a 2 s  . co  m*/
    return false;
}

From source file:com.viacoin.wallet.WalletApplication.java

@Override
public void onCreate() {
    new LinuxSecureRandom(); // init proper random number generator

    initLogging();// w ww. j  a  v  a  2 s . c  o  m

    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().permitDiskReads()
            .permitDiskWrites().penaltyLog().build());

    Threading.throwOnLockCycles();

    log.info("=== starting app using configuration: {}, {}", Constants.TEST ? "test" : "prod",
            Constants.NETWORK_PARAMETERS.getId());

    super.onCreate();

    packageInfo = packageInfoFromContext(this);

    CrashReporter.init(getCacheDir());

    Threading.uncaughtExceptionHandler = new Thread.UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(final Thread thread, final Throwable throwable) {
            log.info("bitcoinj uncaught exception", throwable);
            CrashReporter.saveBackgroundTrace(throwable, packageInfo);
        }
    };

    initMnemonicCode();

    config = new Configuration(PreferenceManager.getDefaultSharedPreferences(this));
    activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);

    blockchainServiceIntent = new Intent(this, BlockchainServiceImpl.class);
    blockchainServiceCancelCoinsReceivedIntent = new Intent(BlockchainService.ACTION_CANCEL_COINS_RECEIVED,
            null, this, BlockchainServiceImpl.class);
    blockchainServiceResetBlockchainIntent = new Intent(BlockchainService.ACTION_RESET_BLOCKCHAIN, null, this,
            BlockchainServiceImpl.class);

    walletFile = getFileStreamPath(Constants.Files.WALLET_FILENAME_PROTOBUF);

    loadWalletFromProtobuf();

    config.updateLastVersionCode(packageInfo.versionCode);

    afterLoadWallet();
}

From source file:com.android.contacts.common.list.ShortcutIntentBuilder.java

public ShortcutIntentBuilder(Context context, OnShortcutIntentCreatedListener listener) {
    mContext = context;/*from  w  ww.  jav a 2s.com*/
    mListener = listener;

    mResources = context.getResources();
    final ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    mIconSize = mResources.getDimensionPixelSize(R.dimen.shortcut_icon_size);
    if (mIconSize == 0) {
        mIconSize = am.getLauncherLargeIconSize();
    }
    mIconDensity = am.getLauncherLargeIconDensity();
    mOverlayTextBackgroundColor = mResources.getColor(R.color.shortcut_overlay_text_background);
}

From source file:cn.whereyougo.framework.utils.PackageManagerUtil.java

/**
 * ????/*w w w .  ja v  a 2  s .c  o  m*/
 * 
 * @param context
 */
public static boolean isAppOnForeground(final Context context) {
    ActivityManager activityManager = (ActivityManager) context.getApplicationContext()
            .getSystemService(Context.ACTIVITY_SERVICE);
    String packageName = context.getApplicationContext().getPackageName();
    List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
    if (appProcesses != null) {
        for (RunningAppProcessInfo appProcess : appProcesses) {
            // The name of the process that this object is associated with.
            if (appProcess.processName.equals(packageName)
                    && appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
                return true;
            }
        }
    }
    return false;
}

From source file:com.android.leanlauncher.IconCache.java

public IconCache(Context context) {
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

    mContext = context;/*from   w ww . j  a va 2s . c o  m*/
    mPackageManager = context.getPackageManager();
    mUserManager = UserManagerCompat.getInstance(mContext);
    mLauncherApps = LauncherAppsCompat.getInstance(mContext);
    mIconDpi = activityManager.getLauncherLargeIconDensity();

    // need to set mIconDpi before getting default icon
    UserHandleCompat myUser = UserHandleCompat.myUserHandle();
    mDefaultIcons.put(myUser, makeDefaultIcon(myUser));
    mCurrentIconTheme = PreferenceManager.getDefaultSharedPreferences(context)
            .getString(context.getString(R.string.pref_icon_theme_key), "");
    getIconPackResources();
}

From source file:systems.soapbox.ombuds.client.WalletApplication.java

@Override
public void onCreate() {
    new LinuxSecureRandom(); // init proper random number generator

    initLogging();/* w w w.j  av a2s  . c  om*/

    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().permitDiskReads()
            .permitDiskWrites().penaltyLog().build());

    Threading.throwOnLockCycles();

    log.info("=== starting app using configuration: {}, {}", Constants.TEST ? "test" : "prod",
            Constants.NETWORK_PARAMETERS.getId());

    super.onCreate();

    packageInfo = packageInfoFromContext(this);

    CrashReporter.init(getCacheDir());

    Threading.uncaughtExceptionHandler = new Thread.UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(final Thread thread, final Throwable throwable) {
            log.info("bitcoinj uncaught exception", throwable);
            CrashReporter.saveBackgroundTrace(throwable, packageInfo);
        }
    };

    initMnemonicCode();

    config = new Configuration(PreferenceManager.getDefaultSharedPreferences(this), getResources());
    activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);

    blockchainServiceIntent = new Intent(this, BlockchainServiceImpl.class);
    blockchainServiceCancelCoinsReceivedIntent = new Intent(BlockchainService.ACTION_CANCEL_COINS_RECEIVED,
            null, this, BlockchainServiceImpl.class);
    blockchainServiceResetBlockchainIntent = new Intent(BlockchainService.ACTION_RESET_BLOCKCHAIN, null, this,
            BlockchainServiceImpl.class);

    walletFile = getFileStreamPath(Constants.Files.WALLET_FILENAME_PROTOBUF);

    loadWalletFromProtobuf();

    if (config.versionCodeCrossed(packageInfo.versionCode, VERSION_CODE_SHOW_BACKUP_REMINDER)
            && !wallet.getImportedKeys().isEmpty()) {
        log.info("showing backup reminder once, because of imported keys being present");
        config.armBackupReminder();
    }

    config.updateLastVersionCode(packageInfo.versionCode);

    afterLoadWallet();

    cleanupFiles();
}

From source file:com.example.product.GcmIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();//from   w ww.  j  a v a 2  s  .  co m
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
    // The getMessageType() intent parameter must be the intent you received
    // in your BroadcastReceiver.
    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
        /*
         * Filter messages based on message type. Since it is likely that GCM will be
         * extended in the future with new message types, just ignore any message types you're
         * not interested in, or that you don't recognize.
         */
        if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
            Log.e(TAG, "GCM_MESSAGE_TYPE_SEND_ERROR");
            //do nothing              
            //sendNotification("Send error: " + extras.toString());
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
            Log.e(TAG, "GCM_MESSAGE_TYPE_DELETED");
            //do nothing            
            //sendNotification("Deleted messages on server: " + extras.toString());
            // If it's a regular GCM message, do some work.
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {

            //? ?? Notification? .              
            // This loop represents the service doing some work.
            /*
             for (int i = 0; i < 5; i++) {
            Log.i(TAG, "Working... " + (i + 1)
                    + "/5 @ " + SystemClock.elapsedRealtime());
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
            }
             }
             */

            Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());
            // Post notification of received message.
            //sendNotification("Received: " + extras.toString());                
            //test sendNotification
            sendNotification(extras);

            Log.i(TAG, "Received: " + extras.toString());

            //??  
            if (!isScreenOn(this)) {

                Log.i(TAG, "screen is off");

                //test
                Intent popupIntent = new Intent(this, ActivityPopUp.class).putExtras(extras)
                        .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                //  .
                this.startActivity(popupIntent);

            }
            //??  
            else {
                ActivityManager am = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);
                List<RunningTaskInfo> runList = am.getRunningTasks(10);
                ComponentName name = runList.get(0).topActivity;
                String className = name.getClassName();
                boolean isAppRunning = false;

                Log.i(TAG, "className ==" + className);
                //? ?? AcitivityPopUp ?
                if (className.equals("com.example.product.ActivityPopUp")) {
                    isAppRunning = true;
                }

                //?? ?
                if (isAppRunning == true) {
                    Log.i(TAG, "screen is off, but popup is on");

                    //test
                    Intent popupIntent = new Intent(this, ActivityPopUp.class).putExtras(extras)
                            .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    //  .
                    this.startActivity(popupIntent);
                    // ? ?  ? 
                }
                //? ? ? 
                else {

                    // ? ? ?  ? 

                }
            }

        }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}

From source file:de.langerhans.wallet.WalletApplication.java

@Override
public void onCreate() {
    new LinuxSecureRandom(); // init proper random number generator

    initLogging();//from   w w w . j  a  va  2 s  .com

    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().permitDiskReads()
            .permitDiskWrites().penaltyLog().build());

    Threading.throwOnLockCycles();

    log.info("=== starting app using configuration: {}, {}", Constants.TEST ? "test" : "prod",
            Constants.NETWORK_PARAMETERS.getId());

    super.onCreate();

    packageInfo = packageInfoFromContext(this);

    CrashReporter.init(getCacheDir());

    Threading.uncaughtExceptionHandler = new Thread.UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(final Thread thread, final Throwable throwable) {
            log.info("bitcoinj uncaught exception", throwable);
            CrashReporter.saveBackgroundTrace(throwable, packageInfo);
        }
    };

    initMnemonicCode();

    config = new Configuration(PreferenceManager.getDefaultSharedPreferences(this));
    activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);

    blockchainServiceIntent = new Intent(this, BlockchainServiceImpl.class);
    blockchainServiceCancelCoinsReceivedIntent = new Intent(BlockchainService.ACTION_CANCEL_COINS_RECEIVED,
            null, this, BlockchainServiceImpl.class);
    blockchainServiceResetBlockchainIntent = new Intent(BlockchainService.ACTION_RESET_BLOCKCHAIN, null, this,
            BlockchainServiceImpl.class);

    walletFile = getFileStreamPath(Constants.Files.WALLET_FILENAME_PROTOBUF);

    loadWalletFromProtobuf();

    if (config.versionCodeCrossed(packageInfo.versionCode, VERSION_CODE_SHOW_BACKUP_REMINDER)
            && !wallet.getImportedKeys().isEmpty()) {
        log.info("showing backup reminder once, because of imported keys being present");
        config.armBackupReminder();
    }

    config.updateLastVersionCode(packageInfo.versionCode);

    afterLoadWallet();

    cleanupFiles();
}