Launch intent to run app in background on Android

I am using Wikitude API 1.1 as an AR viewer in my application. The problem with Wikitude, if I did not start the Wikitude application from the moment the phone loads, I get a NullPointerException every time I start my own application.

So, I think that if I can start my application first, and they checked whether Wikitude is installed and running. If it is not installed, go to the n download market. If it does not work, we must run it right in the background so that my application does not lose focus.

    // Workaround for Wikitude
    this.WIKITUDE_PACKAGE_NAME = "com.wikitude";
    PackageManager pacMan = Poligamy.this.getPackageManager();
    try {
        PackageInfo pacInfo = pacMan.getPackageInfo(this.WIKITUDE_PACKAGE_NAME, pacMan.GET_SERVICES);
        Log.i("CheckWKTD", "Wikitude is Installed");
        ActivityManager aMan = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
        List<RunningAppProcessInfo> runningApps = aMan.getRunningAppProcesses();
        int numberOfApps = runningApps.size();

        for(int i=0; i<numberOfApps; i++) {
            if(runningApps.get(i).processName.equals(this.WIKITUDE_PACKAGE_NAME)) {
                this.WIKITUDE_RUNNING = 1;
                Log.i("CheckWKTD", "Wikitude is Running");
            }
        }
        if(this.WIKITUDE_RUNNING == 0) {
            Log.i("CheckWKTD", "Wikitude is NOT Running");
            /*final Intent wIntent = new Intent(Intent.ACTION_MAIN, null);
            wIntent.addCategory(Intent.CATEGORY_LAUNCHER);
            final ComponentName cn = new ComponentName("com.wikitude", 
                    "com.mobilizy.wikitudepremium.initial.Splash");
            wIntent.setComponent(cn);
            wIntent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION);
            startActivityIfNeeded(wIntent, 0);*/
        }
    } catch (NameNotFoundException e) {
        // TODO Auto-generated catch block
        Log.i("CheckWKTD", "Wikitude is NOT Installed");
        e.printStackTrace();
        //finish();
    }

The commented part of the block is the intention to launch Wikitude. But I have always failed to limit Wikitude to the background. Any help? Thanks before.

Best, Tista p>

+3
1

, " ".

NullPointerException, WIKITUDE , , .

+1

Source: https://habr.com/ru/post/1745603/


All Articles