简体   繁体   English

有没有办法检查Twitter应用程序是否在后台运行

[英]Is there any way to check if a twitter app is running in the background

我想知道是否有办法检查Twitter应用程序是否在后台运行。

You can use the Running Processes: 您可以使用正在运行的进程:

ActivityManager activityManager = (ActivityManager) this.getSystemService( ACTIVITY_SERVICE );
List<RunningAppProcessInfo> procInfos = actvityManager.getRunningAppProcesses();
for(int i = 0; i < procInfos.size(); i++){
    if(procInfos.get(i).processName.equals("com.twitter.android")) {
        Toast.makeText(getApplicationContext(), "Twitter is running", Toast.LENGTH_LONG).show();
    }
}

I'm not entirely sure why you would want to know this though. 我不完全确定为什么你会想知道这个。

EDIT: 编辑:

Since you only need to know if it is installed, this code will suit you better: 由于您只需要知道它是否已安装,因此此代码更适合您:

private boolean isTwitterInstalled() {
    PackageManager pm = getPackageManager();
    boolean twitter_installed = false;
    try {
        pm.getPackageInfo("com.twitter.android", PackageManager.GET_ACTIVITIES);
        twitter_installed = true;
    } catch (PackageManager.NameNotFoundException e) {
        twitter_installed = false;
    }
    return app_installed;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 检查我的应用程序是否在后台运行 - check if my app is running in the background 如何检查是否正在运行任何后台任务? - How to check if there is any background task running? Android Marshmallow 6.0,检查后台正在运行的应用程序 - Android Marshmallow 6.0 , check running app in background 如何检查应用程序是否在BroadcastReceiver中的前台后台运行 - How to check app is running in background of foreground in BroadcastReceiver 检查应用程序是在前台还是后台运行(使用同步适配器) - Check if app is running in foreground or background (with sync adapter) Kivy 应用程序有什么方法可以继续在后台工作吗? - Is there any way for Kivy app to continue working in background? 有没有办法让后台应用程序在其他应用程序运行时显示某些内容? - is there a way to let an background app display something when other app is running? 当应用未在后台运行时,如何使用通知打开任何活动? - How to open any Activity using notification when app is not running in Background? 在android应用程序的后台运行服务以检查网络连接 - running service in background of android app to check for network connection 如何检查任何后台应用程序是否使用麦克风 - How to check whether microphone is used by any background app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM