Skip to content

Instantly share code, notes, and snippets.

@ShongSu
ShongSu / fcmSend.js
Created September 23, 2016 16:10
NodeJS code to send google FCM notification
"use strict";
var gcm = require('node-gcm');
var msgcall = new gcm.Message({
data: {
key1: 'Pengyu Chen',
key2: 'Room 2'
@ShongSu
ShongSu / isBackgroundRunning.java
Created September 6, 2016 18:54
Check if your Android Activity is running in background
public static boolean isBackgroundRunning(Context context) {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> runningProcesses = am.getRunningAppProcesses();
for (ActivityManager.RunningAppProcessInfo processInfo : runningProcesses) {
if (processInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
for (String activeProcess : processInfo.pkgList) {
if (activeProcess.equals(context.getPackageName())) {
//If your app is the process in foreground, then it's not in running in background
return false;
}