List of usage examples for android.app ActivityManager getRunningTasks
@Deprecated public List<RunningTaskInfo> getRunningTasks(int maxNum) throws SecurityException
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 ww .jav a2 s.c om 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:org.deviceconnect.android.deviceplugin.host.profile.HostKeyEventProfile.java
/** * Execute Key Event Activity./* ww w. ja v a 2 s .com*/ * * @param serviceId service ID. * @return Always true. */ private boolean execKeyEventActivity(final String serviceId) { ActivityManager mActivityManager = (ActivityManager) getContext() .getSystemService(Service.ACTIVITY_SERVICE); String mClassName = mActivityManager.getRunningTasks(1).get(0).topActivity.getClassName(); if (!(KeyEventProfileActivity.class.getName().equals(mClassName))) { Intent mIntent = new Intent(); mIntent.setClass(getContext(), KeyEventProfileActivity.class); mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mIntent.putExtra(DConnectMessage.EXTRA_SERVICE_ID, serviceId); this.getContext().startActivity(mIntent); } return true; }
From source file:com.stikyhive.gcm.MyGcmListenerService.java
public boolean checkApp() { ActivityManager am = (ActivityManager) getApplicationContext().getSystemService(ACTIVITY_SERVICE); // get the info from the currently running task List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1); // ActivityManager activityManager = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE); // List<ActivityManager.RunningTaskInfo> services = activityManager // .getRunningTasks(Integer.MAX_VALUE); ComponentName componentInfo = taskInfo.get(0).topActivity; Log.i("Package Activity", " " + componentInfo.getPackageName()); Log.i("Class Activity", " " + componentInfo.getClassName()); if (componentInfo.getClassName().equalsIgnoreCase("com.stikyhive.stikyhive.StikyChatMoreActivity")) { Log.i(TAG, "Chat More Activity"); StikyChatMoreActivity.flagGCM = true; flagNoti = false;// ww w .j av a 2 s. c o m Intent registrationComplete = new Intent(QuickstartPreferences.REGISTRATION_COMPLETE); LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(registrationComplete); return false; } else if (componentInfo.getClassName().equalsIgnoreCase("com.stikyhive.stikyhive.ChattingActivity")) { Log.i("TAG", componentInfo.getClass() + " "); Intent registrationComplete = new Intent(QuickstartPreferences.CHAT_REGISTRATION_COMPLETE); LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(registrationComplete); return true; } else if (componentInfo.getPackageName() != "com.stikyhive.stikyhive") { flagNoti = true; return false; } else { flagNoti = false; return false; } }
From source file:com.openerp.services.MessageSyncService.java
/** * Perform sync./*from www . j ava 2 s . co m*/ * * @param context the context * @param account the account * @param extras the extras * @param authority the authority * @param provider the provider * @param syncResult the sync result */ public void performSync(Context context, Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { Intent intent = new Intent(); Intent updateWidgetIntent = new Intent(); updateWidgetIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE); updateWidgetIntent.putExtra(MessageWidget.ACTION_MESSAGE_WIDGET_UPDATE, true); intent.setAction(SyncFinishReceiver.SYNC_FINISH); OEUser user = OpenERPAccountManager.getAccountDetail(context, account.name); try { MessageDB msgDb = new MessageDB(context); msgDb.setAccountUser(user); OEHelper oe = msgDb.getOEInstance(); if (oe == null) { return; } int user_id = user.getUser_id(); // Updating User Context for OE-JSON-RPC JSONObject newContext = new JSONObject(); newContext.put("default_model", "res.users"); newContext.put("default_res_id", user_id); OEArguments arguments = new OEArguments(); // Param 1 : ids arguments.addNull(); // Param 2 : domain OEDomain domain = new OEDomain(); // Data limit. PreferenceManager mPref = new PreferenceManager(context); int data_limit = mPref.getInt("sync_data_limit", 60); domain.add("create_date", ">=", OEDate.getDateBefore(data_limit)); if (!extras.containsKey("group_ids")) { // Last id JSONArray msgIds = new JSONArray(); for (OEDataRow row : msgDb.select()) { msgIds.put(row.getInt("id")); } domain.add("id", "not in", msgIds); domain.add("|"); // Argument for check partner_ids.user_id is current user domain.add("partner_ids.user_ids", "in", new JSONArray().put(user_id)); domain.add("|"); // Argument for check notification_ids.partner_ids.user_id // is // current user domain.add("notification_ids.partner_id.user_ids", "in", new JSONArray().put(user_id)); // Argument for check author id is current user domain.add("author_id.user_ids", "in", new JSONArray().put(user_id)); } else { JSONArray group_ids = new JSONArray(extras.getString("group_ids")); // Argument for group model check domain.add("model", "=", "mail.group"); // Argument for group model res id domain.add("res_id", "in", group_ids); } arguments.add(domain.getArray()); // Param 3 : message_unload_ids arguments.add(new JSONArray()); // Param 4 : thread_level arguments.add(true); // Param 5 : context arguments.add(oe.updateContext(newContext)); // Param 6 : parent_id arguments.addNull(); // Param 7 : limit arguments.add(50); List<Integer> ids = msgDb.ids(); if (oe.syncWithMethod("message_read", arguments)) { int affected_rows = oe.getAffectedRows(); List<Integer> affected_ids = oe.getAffectedIds(); boolean notification = true; ActivityManager am = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1); ComponentName componentInfo = taskInfo.get(0).topActivity; if (componentInfo.getPackageName().equalsIgnoreCase("com.openerp")) { notification = false; } if (notification && affected_rows > 0) { OENotificationHelper mNotification = new OENotificationHelper(); Intent mainActiivty = new Intent(context, MainActivity.class); mNotification.setResultIntent(mainActiivty, context); String notify_title = context.getResources().getString(R.string.messages_sync_notify_title); notify_title = String.format(notify_title, affected_rows); String notify_body = context.getResources().getString(R.string.messages_sync_notify_body); notify_body = String.format(notify_body, affected_rows); mNotification.showNotification(context, notify_title, notify_body, authority, R.drawable.ic_oe_notification); } intent.putIntegerArrayListExtra("new_ids", (ArrayList<Integer>) affected_ids); } List<Integer> updated_ids = updateOldMessages(msgDb, oe, user, ids); intent.putIntegerArrayListExtra("updated_ids", (ArrayList<Integer>) updated_ids); } catch (Exception e) { e.printStackTrace(); } if (user.getAndroidName().equals(account.name)) { context.sendBroadcast(intent); context.sendBroadcast(updateWidgetIntent); } }
From source file:org.openmidaas.app.activities.AuthorizationActivity.java
public 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 ww w. j a va 2 s.c o m } return false; }
From source file:cn.sharesdk.analysis.server.ServiceHelper.java
public boolean isAppExit() { if (context == null) { Ln.e("getActivityName", "context is null that do not get the package's name "); return true; }/*from w w w.j a v a 2 s . co m*/ String packageName = context.getPackageName(); ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); if (deviceHelper.checkPermissions("android.permission.GET_TASKS")) { ComponentName cn = am.getRunningTasks(1).get(0).topActivity; boolean isEqual = packageName.equals(cn.getPackageName()); return !isEqual; } else { Ln.e("lost permission", "android.permission.GET_TASKS"); return true; } }
From source file:ru.orangesoftware.financisto2.activity.FlowzrSyncActivity.java
public void setIsFinished() { setReady();// w ww .j a va 2 s. com ActivityManager am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE); List<RunningTaskInfo> taskInfo = am.getRunningTasks(1); ComponentName componentInfo = taskInfo.get(0).topActivity; if (taskInfo.get(0).topActivity.getClassName().equals(this.getClass().getName())) { startActivity(new Intent(getApplicationContext(), MainActivity.class)); } else if (taskInfo.get(0).topActivity.getShortClassName().equals(".BudgetListActivity.class")) { startActivity(new Intent(getApplicationContext(), BudgetListActivity.class)); } }
From source file:cl.iluminadoschile.pako.floatingdiv.CustomOverlayService.java
private boolean ingress_running_in_foreground() { String ingress_app_name = this.getApplicationContext().getString(R.string.ingress_process_name); ActivityManager am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE); // The first in the list of RunningTasks is always the foreground task. int index2ask = 0; if (overlayView.isVisible()) { index2ask = 1;/*from ww w . j ava2 s . c o m*/ } ActivityManager.RunningTaskInfo foregroundTaskInfo = am.getRunningTasks(index2ask + 1).get(0); String foregroundTaskPackageName = foregroundTaskInfo.topActivity.getPackageName(); PackageManager pm = this.getPackageManager(); PackageInfo foregroundAppPackageInfo = null; try { foregroundAppPackageInfo = pm.getPackageInfo(foregroundTaskPackageName, 0); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } String foregroundTaskAppName = foregroundAppPackageInfo.applicationInfo.loadLabel(pm).toString(); Log.i("julin", foregroundTaskAppName + " " + index2ask + " " + (overlayView.isVisible() ? "SI" : "NO")); return foregroundTaskAppName.equals("Ingress"); }
From source file:com.tasomaniac.openwith.resolver.ResolverActivity.java
@SuppressWarnings("deprecation") private String getCallerPackagerLegacy() { String callerPackage;//from w w w.j ava 2 s . co m ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE); final List<ActivityManager.RunningTaskInfo> runningTasks = am.getRunningTasks(1); final ComponentName topActivity = runningTasks.get(0).baseActivity; callerPackage = topActivity.getPackageName(); return callerPackage; }
From source file:net.wespot.pim.view.InqCommunicateFragment.java
public boolean isPimRunning() { ActivityManager activityManager = (ActivityManager) ARL.getContext() .getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> services = activityManager.getRunningTasks(Integer.MAX_VALUE); boolean isActivityFound = false; if (services.get(0).topActivity.getPackageName().toString() .equalsIgnoreCase(ARL.getContext().getPackageName().toString())) { return true; } else {/*from w ww. j a v a 2 s . c o m*/ return false; } }