从 Android 应用程序启动未知活动

发布于 2024-08-27 12:54:57 字数 386 浏览 6 评论 0原文

我想制作一个 Android 应用程序,显示应用程序列表(从 Android 市场下载)并启动用户选择的应用程序。根据我所读到的内容,我必须使用这样的意图:

  Intent intent = new Intent();
  intent.setClassName(packageName, className);
  startActivity(intent);

我只想能够启动应用程序,而不是它们可能具有的特定活动。

我的问题是:如果我不知道这些应用程序的 packageName 或 className,我如何启动这些应用程序?或者也许,如果它是我没有开发的闭源应用程序,我如何才能知道它们的 className 和 packageName 。

谢谢。

I want to make an android application that shows a listing of applications (downloaded from the android market) and launches the one that the user selects. From what I've read, I'd have to use intents like this:

  Intent intent = new Intent();
  intent.setClassName(packageName, className);
  startActivity(intent);

I just want to be able to launch the applications, not a specific activity that they could have.

My question is: how could I launch these applications if I don't know their packageName or className? or maybe, how could I get to know their className and packageName, if it's a closed source application that I didn't develop.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

百合的盛世恋 2024-09-03 12:54:57

使用PackageManager来查找已安装的应用程序等。事实上,你会发现这本书示例项目确实相当多你需要的东西。

Use PackageManager to find out the installed applications and such. In fact, you will find this book sample project does a fair bit of what you need.

小清晰的声音 2024-09-03 12:54:57

简而言之,你不能。但是,Android 会让您获得已安装软件包的列表及其完全限定的类名。查看此链接的代码,了解如何获取此软件包列表的示例。据我所知,无法确定该软件包的安装位置,但您可以将其与设备上预安装的已知应用程序列表进行比较,并将其过滤掉。这个想法是,如果它不是预安装的应用程序,它很可能是通过市场安装的。

In short, you can't. But, Android will let you get a hold of a list of installed packages along with their fully qualified class names. Check out the code at this link for an example of how to get this package listing. As far as I know, there's no way to determine from where the package was installed, but what you could do is compare it against a list of known applications to be preinstalled on the device and filter those out. The idea being that if it's not a preinstalled application, it was likely installed through the marketplace.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文