gpt4 book ai didi

android - 检查应用程序是否由另一个执行

转载 作者:行者123 更新时间:2023-11-30 02:10:36 24 4
gpt4 key购买 nike

我想知道我的应用程序是否被另一个应用程序执行

我试了好几种方法都没有找到解决办法

我试过了但是返回了相同的值请帮助我!代码:

public class MainActivity extends Activity {

public static boolean isinint;

@Override
protected void onResume() {
super.onResume();

Intent intent = getIntent();
// check if any application has executed your app
if (intent != null && intent.getType() != null) {
isinint = true;
Toast.makeText(getApplicationContext(), "is:" + isinint, Toast.LENGTH_LONG).show();
} else {
isinint = false;
Toast.makeText(getApplicationContext(), "is:" + isinint, Toast.LENGTH_LONG).show();
}
}
}

最佳答案

This answer from dhaval 将为您工作

Try this code:

      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.android.browser"))
{
Toast.makeText(getApplicationContext(), "Browser is running", Toast.LENGTH_LONG).show();
}
}

将 com.android.browser 替换为您的应用进程名称。

关于android - 检查应用程序是否由另一个执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30163835/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com