在 Android 中启动应用程序到后台的 Intent
我在我的应用程序中使用 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();
}
我阻止评论的部分是启动维基百科的意图。但我总是未能将维基百科限制在背景中。有什么帮助吗?先谢谢了。
最好的, 蒂斯塔
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.
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();
}
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不存在“直接运行到后台”这样的事情。
我会通过联系 WIKITUDE 来重点解决您的
NullPointerException
问题,并找出在他们的应用程序尚未运行的情况下您为何会收到此异常的原因。There is no such thing as "run it straight to background".
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.