启动一个意图启动一个应用程序在Android的后台 [英] Starting an Intent to Launch an app to Background in Android

查看:196
本文介绍了启动一个意图启动一个应用程序在Android的后台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是Wikitude API 1.1在我的应用程序的AR浏览器。与Wikitude问题,如果我还没有推出,因为手机的启动实际Wikitude应用程序,我会得到一个NullPointerException异常每次我开始我自己的应用程序。

I'm using Wikitude API 1.1 as an AR viewer in my application. The problem with Wikitude, if I haven't launched the actual Wikitude application since the phone's bootup, I will get a NullPointerException everytime I start my own application.

所以我想,如果我可以先开始我的应用程序并检查是否安装了Wikitude和或跑步。如果它没有安装,进入市场N下载。如果它没有运行,那么我们就应该直接运行它的背景,使我的应用程序不会失去其焦点。

So I figure if I can start my app first and them check if Wikitude is installed and or running. If it's not installed, go to market n download. If it's not running, then we should run it straight to background so that my app doesn't loose its 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();
    }

我阻止注释部分是开始Wikitude的意图。但我始终没制约Wikitude背景。任何帮助吗?前感谢。

The part I block commented is the intent to start Wikitude. But I always failed in restricting Wikitude to background. Any help? Thanks before.

最佳,
蒂斯达

Best, Tista

推荐答案

有没有这样的事情直接运行它的背景。

There is no such thing as "run it straight to background".

我将专注于固定你的 NullPointerException异常通过联系WIKITUDE和弄清楚为什么你得到它,如果他们的应用程序还没有运行过。

I would focus on fixing your NullPointerException by contacting WIKITUDE and figuring out why you are getting it if their app has not yet been run.

这篇关于启动一个意图启动一个应用程序在Android的后台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆