【问题标题】:Check if app is executed by another检查应用程序是否由另一个执行
【发布时间】:2015-07-21 17:32:46
【问题描述】:

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

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

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

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

【问题讨论】:

标签: android android-intent launch


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

【讨论】:

    猜你喜欢
    • 2017-01-02
    • 2014-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多