Android的 - 如何开始与包名的第三方应用程序?第三方、应用程序、Android

2023-09-07 04:50:11 作者:我拽我实力

我想知道如何从我的应用程序中使用包名启动其他应用程序。

I am wondering how to start an another app from my app using package name.

我在字符串格式封装的名字像

I have package name in string format like

String pkgName = "com.example.appName";

这就是为什么我无法获取类名或任何其他有价值的信息,我可以用它来作出适当的意图开始活动。

That is why i am unable to fetch class name or any other valuable details from it which i can use to make a proper intent to start an activity.

不知道如何解决这个问题。请帮助!

Any idea how to solve this problem. Please Help!!

感谢。

推荐答案

好了,你不希望获取任何类的名称。你要做的是创建一个意图活动的可以推出的这款包的名称(他们需要有具体的)。在一个单一的线,你需要做的是:

well, you don't want to fetch ANY class name. What you want to do is to create an Intent out of this package name with Activity's that can be launched (they need to have specific category). In a single line, what you need to do is:

startActivity(getPackageManager().getLaunchIntentForPackage("com.example.appName"));

检查该文件PackageManager.getLaunchIntentForPackage.一般来说,PackageManager有很多有趣的方法来启动应用程序。 这里是我的博客文章这样做正是对多个包。

Check the documentation for PackageManager.getLaunchIntentForPackage. Generally speaking, PackageManager has a lot of interesting methods for launching apps. Here is my blog entry doing exactly that for multiple packages.