判断app是否已启动
2016-07-04 17:11
357 查看
最近做推送通知,需要判断应用程序是否已经启动,下面是一个方法可以判断本应用是否启动
/** * packName 应用的包名 * 返回值 */ public static boolean isAppAlive(Context context, String packageName){ ActivityManager activityManager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningAppProcessInfo> processInfos = activityManager.getRunningAppProcesses(); for(int i = 0; i < processInfos.size(); i++){ if(processInfos.get(i).processName.equals(packageName)){ Log.i("NotificationLaunch", String.format("the %s is running, isAppAlive return true", packageName)); return true; } } Log.i("NotificationLaunch", String.format("the %s is not running, isAppAlive return false", packageName)); return false; }
相关文章推荐
- 016.View的测绘基础MeasureSpec
- AndroidStudio集成ShareSDK社会化分享
- android xml解析
- 关于微信网页调用js-sdk相关接口注意事项目(一级域名与二级域名互相干扰!!!)
- Android5.0+(CollapsingToolbarLayout)
- 【android】存储数组数据到SharedPreferences
- app测试总结
- 移动端WEB开发,click,touch,tap事件浅析
- IOS 在启动图之后加入广告或加入伪启动动画
- 微信webview
- AndroidStudio的基本设置
- android jar包 module里配置了可是编译找不到,提示No such file or directory
- 有用的鏈接
- Machine Learning - 第6周(Advice for Applying Machine Learning、Machine Learning System Design)
- 5个常用的Android自动化测试框架介绍
- Android WebView JS 交互 以及 传各种类型到JS函数
- iOS中静态库(static library, .a文件)中的category变得可用
- Android SDK Manager 更新代理配置
- 实现微信透明弹窗
- AndroidStudio删除项目