簡體   English   中英

啟動Intent以在Android中啟動應用程序到背景

[英]Starting an Intent to Launch an app to Background in Android

我在我的應用程序中使用Wikitude API 1.1作為AR查看器。 Wikitude的問題,如果我從手機啟動后沒有啟動真正的Wikitude應用程序,每次啟動自己的應用程序時,我都會得到一個NullPointerException。

所以我想我是否可以先啟動我的應用程序,然后檢查Wikitude是否已安裝或正在運行。 如果沒有安裝,請進入市場下載。 如果它沒有運行,那么我們應該直接將它運行到后台,以便我的應用程序不會失去焦點。

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

我阻止評論的部分是啟動Wikitude的意圖。 但我始終未能將Wikitude限制為背景。 有幫助嗎? 謝謝你。

最好,蒂斯塔

沒有“直接運行到背景”這樣的事情。

我將專注於修復您的NullPointerException是聯系WIKITUDE,並確定如果他們的應用程序尚未運行,您將獲得它的原因。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM