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.tessoft.nearhere.GcmIntentService.java

private void sendNotification(Bundle extras) {

    String title = extras.getString("title");
    String type = extras.getString("type");
    String msg = extras.getString("message");

    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle(title)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg)
            .setAutoCancel(true);/*  w w  w .  ja v  a2s  . co  m*/

    Intent intent = null;

    boolean isActive = false;

    // check if background
    //        ActivityManager activityManager = (ActivityManager) this.getSystemService( ACTIVITY_SERVICE );
    //        List<RunningAppProcessInfo> procInfos = activityManager.getRunningAppProcesses();
    //        for(int i = 0; i < procInfos.size(); i++)
    //        {
    //            if(procInfos.get(i).processName.equals("com.tessoft.nearhere")) 
    //               isActive = true;
    //        }

    // check if foreground
    ActivityManager activityManager = (ActivityManager) getApplicationContext()
            .getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> services = activityManager.getRunningTasks(Integer.MAX_VALUE);

    if (services.get(0).topActivity.getPackageName().toString()
            .equalsIgnoreCase(getApplicationContext().getPackageName().toString())) {
        isActive = true;
    }

    if (isActive) {
        intent = new Intent("updateUnreadCount");
        intent.putExtra("type", type);
        if ("message".equals(type)) {
            intent.putExtra("fromUserID", extras.getString("fromUserID"));

            Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
            r.play();

            Vibrator v = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
            v.vibrate(500);
        } else if ("postReply".equals(type)) {
            intent.putExtra("postID", extras.getString("postID"));

            Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
            r.play();

            Vibrator v = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
            v.vibrate(500);
        }

        getApplicationContext().sendBroadcast(intent);
    } else {
        if ("message".equals(type)) {
            intent = new Intent(this, UserMessageActivity.class);
            HashMap hash = new HashMap();
            hash.put("fromUserID", extras.getString("fromUserID"));
            hash.put("userID", extras.getString("toUserID"));
            intent.putExtra("messageInfo", hash);
            mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI);
            mBuilder.setVibrate(new long[] { 1000, 1000 });
        } else if ("postReply".equals(type)) {
            intent = new Intent(this, TaxiPostDetailActivity.class);
            intent.putExtra("postID", extras.getString("postID"));
            mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI);
            mBuilder.setVibrate(new long[] { 1000, 1000 });
        } else if ("newPostByDistance".equals(type)) {
            intent = new Intent(this, TaxiPostDetailActivity.class);
            intent.putExtra("postID", extras.getString("postID"));
        } else if ("event".equals(type)) {
            intent = new Intent(this, EventViewerActivity.class);
            intent.putExtra("eventSeq", extras.getString("eventSeq"));
            intent.putExtra("pushNo", extras.getString("pushNo"));

            if ("on".equals(extras.getString("sound")))
                mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI);
            if ("on".equals(extras.getString("vibrate")))
                mBuilder.setVibrate(new long[] { 1000, 1000 });

        } else if ("eventssl".equals(type)) {
            intent = new Intent(this, EventViewerActivity.class);
            intent.putExtra("eventSeq", extras.getString("eventSeq"));
            intent.putExtra("pushNo", extras.getString("pushNo"));
            intent.putExtra("ssl", "true");

            if ("on".equals(extras.getString("sound")))
                mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI);
            if ("on".equals(extras.getString("vibrate")))
                mBuilder.setVibrate(new long[] { 1000, 1000 });

        } else {
            intent = new Intent(this, MainActivity.class);
        }

        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        mBuilder.setContentIntent(contentIntent);
        mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
    }
}

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

/**
 * //from ww w. j  av a 2 s  .co m
 * 
 * @param context
 */
public static void exitApp(final Context context) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (context.getPackageName().equals(service.service.getPackageName())) {
            Intent stopIntent = new Intent();
            ComponentName serviceCMP = service.service;
            stopIntent.setComponent(serviceCMP);
            context.stopService(stopIntent);
            break;
        }
    }
    android.os.Process.killProcess(android.os.Process.myPid());
    System.exit(0);
}

From source file:lewa.support.v7.app.ActionBarActivityDelegateBase.java

public boolean isHome() {
    if (!IS_IGNORE_HOME) {
        try {//w  ww  .ja va2  s  .  c o m

            ActivityManager mActivityManager = (ActivityManager) mActivity
                    .getSystemService(Context.ACTIVITY_SERVICE);
            if (mActivityManager != null) {
                List<RunningTaskInfo> rti = mActivityManager.getRunningTasks(1);
                // boolean isLauncherClass =
                // rti.get(0).topActivity.getClassName()
                // .equals("com.lewa.launcher.Launcher");
                // Log.i(TAG,"isLauncherClass :"+rti.get(0).topActivity.getClassName());
                if (rti != null) {
                    if (rti.size() != 0) {
                        ComponentName cn = rti.get(0).topActivity;
                        if (cn != null) {
                            return getHomes().contains(cn.getPackageName());
                        }

                    }
                }

            }

        } catch (Exception e) {

        }
    }

    //
    return false;
}

From source file:org.chromium.chrome.browser.download.DownloadNotificationService.java

@Override
public void onTaskRemoved(Intent rootIntent) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.AppTask> tasks = am.getAppTasks();
        // In multi-window case, there could be multiple tasks. Only swiping away the last
        // activity should be pause the notification.
        if (tasks.size() > 0)
            return;
    }/*from   w ww  .j  a  va2 s .c o m*/
    mStopPostingProgressNotifications = true;
    // This funcion is called when Chrome is swiped away from the recent apps
    // drawer. So it doesn't catch all scenarios that chrome can get killed.
    // This will only help Android 4.4.2.
    onBrowserKilled();
}

From source file:cn.edu.wyu.documentviewer.RecentLoader.java

public RecentLoader(Context context, RootsCache roots, State state) {
    super(context);
    mRoots = roots;/*from  ww w .  j a  v a2s. co  m*/
    mState = state;

    // Keep clients around on high-RAM devices, since we'd be spinning them
    // up moments later to fetch thumbnails anyway.
    final ActivityManager am = (ActivityManager) getContext().getSystemService(Context.ACTIVITY_SERVICE);
    mQueryPermits = new Semaphore(
            am.isLowRamDevice() ? MAX_OUTSTANDING_RECENTS_SVELTE : MAX_OUTSTANDING_RECENTS);
}

From source file:com.google.android.apps.santatracker.dasherdancer.DasherDancerActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_dasher_dancer);

    mMeasurement = FirebaseAnalytics.getInstance(this);
    MeasurementManager.recordScreenView(mMeasurement, getString(R.string.analytics_screen_dasher));

    AnalyticsManager.initializeAnalyticsTracker(this);
    AnalyticsManager.sendScreenView(R.string.analytics_screen_dasher);

    mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);

    mMemoryCache = new LruCache<Integer, Bitmap>(240) {
        protected void entryRemoved(boolean evicted, Integer key, Bitmap oldValue, Bitmap newValue) {
            if ((oldValue != null) && (oldValue != newValue)) {
                oldValue.recycle();//from   w  w  w  .ja  v  a 2  s  .  c  om
                oldValue = null;
            }
        }
    };

    CharacterAdapter adapter = new CharacterAdapter(sCharacters);
    mPager = (NoSwipeViewPager) findViewById(R.id.character_pager);
    mPager.setAdapter(adapter);
    mPager.setGestureDetectorListeners(this, this, this);
    mPager.setOnPageChangeListener(this);

    mHandler = new Handler(getMainLooper(), this);

    mDetector = new ShakeDetector(this);

    mSoundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 0);
    mSoundIds[0][Character.ANIM_PINCH_IN] = mSoundPool.load(this, R.raw.santa_pinchin, 1);
    mSoundIds[0][Character.ANIM_PINCH_OUT] = mSoundPool.load(this, R.raw.santa_pinchout, 1);
    mSoundIds[0][Character.ANIM_SHAKE] = mSoundPool.load(this, R.raw.santa_shake, 1);
    mSoundIds[0][Character.ANIM_SWIPE_UP] = mSoundPool.load(this, R.raw.santa_swipeup, 1);
    mSoundIds[0][Character.ANIM_SWIPE_LEFT] = mSoundPool.load(this, R.raw.santa_swipeleft, 1);
    mSoundIds[0][Character.ANIM_SWIPE_RIGHT] = mSoundPool.load(this, R.raw.santa_swiperight, 1);
    mSoundIds[0][Character.ANIM_SWIPE_DOWN] = mSoundPool.load(this, R.raw.santa_swipedown, 1);
    mSoundIds[0][Character.ANIM_TAP] = mSoundPool.load(this, R.raw.santa_tap, 1);
    mSoundIds[1][Character.ANIM_PINCH_IN] = mSoundPool.load(this, R.raw.elf_pinchin_ball, 1);
    mSoundIds[1][Character.ANIM_PINCH_OUT] = mSoundPool.load(this, R.raw.elf_pinchout, 1);
    mSoundIds[1][Character.ANIM_SHAKE] = mSoundPool.load(this, R.raw.elf_shake2, 1);
    mSoundIds[1][Character.ANIM_SWIPE_DOWN] = mSoundPool.load(this, R.raw.elf_swipedown2, 1);
    mSoundIds[1][Character.ANIM_SWIPE_UP] = mSoundPool.load(this, R.raw.elf_swipeup2, 1);
    mSoundIds[1][Character.ANIM_SWIPE_LEFT] = mSoundPool.load(this, R.raw.elf_swipeleft, 1);
    mSoundIds[1][Character.ANIM_SWIPE_RIGHT] = mSoundPool.load(this, R.raw.elf_swiperight, 1);
    mSoundIds[1][Character.ANIM_TAP] = mSoundPool.load(this, R.raw.elf_tap3, 1);
    mSoundIds[2][Character.ANIM_PINCH_IN] = mSoundPool.load(this, R.raw.reindeer_pinchin, 1);
    mSoundIds[2][Character.ANIM_PINCH_OUT] = mSoundPool.load(this, R.raw.reindeer_pinchout, 1);
    mSoundIds[2][Character.ANIM_SHAKE] = mSoundPool.load(this, R.raw.reindeer_shake, 1);
    mSoundIds[2][Character.ANIM_SWIPE_UP] = mSoundPool.load(this, R.raw.reindeer_swipeup, 1);
    mSoundIds[2][Character.ANIM_SWIPE_DOWN] = mSoundPool.load(this, R.raw.reindeer_swipedown, 1);
    mSoundIds[2][Character.ANIM_SWIPE_LEFT] = mSoundPool.load(this, R.raw.reindeer_swipeleft, 1);
    mSoundIds[2][Character.ANIM_SWIPE_RIGHT] = mSoundPool.load(this, R.raw.reindeer_swiperight, 1);
    mSoundIds[2][Character.ANIM_TAP] = mSoundPool.load(this, R.raw.reindeer_tap2, 1);
    mSoundIds[3][Character.ANIM_PINCH_IN] = mSoundPool.load(this, R.raw.snowman_pinchin, 1);
    mSoundIds[3][Character.ANIM_PINCH_OUT] = mSoundPool.load(this, R.raw.snowman_pinchout, 1);
    mSoundIds[3][Character.ANIM_SHAKE] = mSoundPool.load(this, R.raw.snowman_shake, 1);
    mSoundIds[3][Character.ANIM_SWIPE_UP] = mSoundPool.load(this, R.raw.snowman_swipeup, 1);
    mSoundIds[3][Character.ANIM_SWIPE_DOWN] = mSoundPool.load(this, R.raw.snowman_swipedown, 1);
    mSoundIds[3][Character.ANIM_SWIPE_LEFT] = mSoundPool.load(this, R.raw.snowman_swipeleft, 1);
    mSoundIds[3][Character.ANIM_SWIPE_RIGHT] = mSoundPool.load(this, R.raw.snowman_swiperight, 1);
    mSoundIds[3][Character.ANIM_TAP] = mSoundPool.load(this, R.raw.snowman_tap, 1);

    mAchievements = new HashSet[4];
    mAchievements[0] = new HashSet<Integer>();
    mAchievements[1] = new HashSet<Integer>();
    mAchievements[2] = new HashSet<Integer>();
    mAchievements[3] = new HashSet<Integer>();

    mProgressAnimator = ObjectAnimator.ofFloat(findViewById(R.id.progress), "rotation", 360f);
    mProgressAnimator.setDuration(4000);
    mProgressAnimator.start();

    mGamesFragment = PlayGamesFragment.getInstance(this, this);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        ImmersiveModeHelper.setImmersiveSticky(getWindow());
        ImmersiveModeHelper.installSystemUiVisibilityChangeListener(getWindow());
    }
}

From source file:com.air.mobilebrowser.ActivityWatchService.java

/**
 * Hide any application that is in the foreground and is not
 * in the white-list, and collapse the status bar.
 *//*from  w  w w.jav a 2  s . c o m*/
private void hideApplications() {
    ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> tasks = am.getRunningTasks(1);

    if (!tasks.isEmpty()) {
        ComponentName topActivity = tasks.get(0).topActivity;

        String packageName = topActivity.getPackageName();

        if (!packageName.equals(getPackageName()) && !mApplicationWhitelist.contains(packageName)) {
            //We hide the activity, by bringing the BrowserActivity back in front.
            Intent intent = new Intent(this, BrowserActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);

            //Visual indicator that we are hiding an app.
            Toast.makeText(this, "Blocked " + packageName, Toast.LENGTH_SHORT).show();
        }
    }

    try {
        final Object service = getSystemService("statusbar");
        Class<?> statusbarManager = Class.forName("android.app.StatusBarManager");

        if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN) {
            final Method collapse = statusbarManager.getMethod("collapse");
            collapse.setAccessible(true);
            collapse.invoke(service);
        } else {
            final Method collapse = statusbarManager.getMethod("collapsePanels");
            collapse.setAccessible(true);
            collapse.invoke(service);
        }
    } catch (Exception ex) {
        Log.e(TAG, "Failed to collapse status bar");
    }

    List<RunningAppProcessInfo> appList = am.getRunningAppProcesses();

    for (RunningAppProcessInfo info : appList) {
        am.killBackgroundProcesses(info.processName);
    }

    appList = am.getRunningAppProcesses();

    for (RunningAppProcessInfo info : appList) {
        if (mAppBlacklist.contains(info.processName)) {
            Intent intent = new Intent(super.getResources().getString(R.string.intent_black_logtag));
            LocalBroadcastManager.getInstance(super.getApplicationContext()).sendBroadcast(intent);
        }
    }

}

From source file:com.llf.android.launcher3.MemoryTracker.java

@Override
public void onCreate() {
    mAm = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);

    // catch up in case we crashed but other processes are still running
    List<ActivityManager.RunningServiceInfo> svcs = mAm.getRunningServices(256);
    for (ActivityManager.RunningServiceInfo svc : svcs) {
        if (svc.service.getPackageName().equals(getPackageName())) {
            Log.v(TAG, "discovered running service: " + svc.process + " (" + svc.pid + ")");
            startTrackingProcess(svc.pid, svc.process,
                    System.currentTimeMillis() - (SystemClock.elapsedRealtime() - svc.activeSince));
        }//from  www  .j a  v  a 2 s  .c om
    }

    List<ActivityManager.RunningAppProcessInfo> procs = mAm.getRunningAppProcesses();
    for (ActivityManager.RunningAppProcessInfo proc : procs) {
        final String pname = proc.processName;
        if (pname.startsWith(getPackageName())) {
            Log.v(TAG, "discovered other running process: " + pname + " (" + proc.pid + ")");
            startTrackingProcess(proc.pid, pname, System.currentTimeMillis());
        }
    }
}

From source file:com.zjxfood.photoview.activity.ViewPagerActivity.java

public static long getmem_UNUSED(Context mContext) {
    long MEM_UNUSED;
    // ActivityManager
    ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
    // ActivityManager.MemoryInfo  

    ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
    am.getMemoryInfo(mi);//from w  ww.  j  a  v  a  2s .  c om

    // ? 

    MEM_UNUSED = mi.availMem / 1024;
    Log.i("MEM_UNUSED", MEM_UNUSED + "==========MEM_UNUSED============");
    return MEM_UNUSED;
}

From source file:com.android.contacts.DynamicShortcuts.java

@VisibleForTesting
public DynamicShortcuts(Context context, ContentResolver contentResolver, ShortcutManager shortcutManager,
        JobScheduler jobScheduler) {//w w w .  j a va2 s  .c  om
    mContext = context;
    mContentResolver = contentResolver;
    mShortcutManager = shortcutManager;
    mJobScheduler = jobScheduler;
    mContentChangeMinUpdateDelay = Flags.getInstance()
            .getInteger(Experiments.DYNAMIC_MIN_CONTENT_CHANGE_UPDATE_DELAY_MILLIS);
    mContentChangeMaxUpdateDelay = Flags.getInstance()
            .getInteger(Experiments.DYNAMIC_MAX_CONTENT_CHANGE_UPDATE_DELAY_MILLIS);
    final ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    mIconSize = context.getResources().getDimensionPixelSize(R.dimen.shortcut_icon_size);
    if (mIconSize == 0) {
        mIconSize = am.getLauncherLargeIconSize();
    }
}