从代码启动android应用程序

Ben*_*ácz 5 android android-intent android-activity

我需要从我的代码中轻松启动应用程序,如Skype或其他应用程序.我在互联网上阅读了一些帖子,但我没有解决方案.我试过这个方法:

Intent startApp = new Intent("com.android.gesture.builder");
startActivity(startApp);
Run Code Online (Sandbox Code Playgroud)

我在try/catch blokk中写了这个,LogCat告诉我:Intent处理的ApplicationNotFound异常.我在Android开发者网站上阅读了"Hello"教程,但是对我的解决方案来说太复杂了......我无法将此应用程序注册到我的清单文件中.我想我需要实现一个新的类,它从Activity扩展,并实现上面的代码,然后再试一次?请帮帮我,如何从主要活动中轻松启动其他应用程序...

Blu*_*ell 5

你快到了!:

你只需要提供你想要的应用程序的包和类。

// Try
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setComponent(new ComponentName("com.htc.Camera", "com.htc.Camera.Camera"));
startActivity(intent);
// catch not found (only works on HTC phones)
Run Code Online (Sandbox Code Playgroud)

组件名称

我也刚刚看到您可以通过第二种方式做到这一点:

  PackageManager packageManager = getPackageManager();
  startActivity(packageManager.getLaunchIntentForPackage("com.skype.android"));
Run Code Online (Sandbox Code Playgroud)

请参阅:SOQ 参考