检查app是否被其他人执行

时间:2015-05-11 09:19:58

标签: android android-intent launch

我想知道我的应用是否已由其他应用执行

我尝试了几种方法,但我找不到解决方案

我试过这个,但返回相同的值请帮帮我!代码:

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();
        }
    }
}

1 个答案:

答案 0 :(得分:1)

This answer from dhaval将为您效劳

  

试试这段代码:

      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替换为您的应用进程名称。