查找 Android 应用程序包名称以使用 Intent 从网络启动 Market 应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2789462/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 07:24:17  来源:igfitidea点击:

Find package name for Android apps to use Intent to launch Market app from web

androidhyperlinkgoogle-playandroid-intent

提问by eom

I'm creating a mobile website that will include a page from which people can download relevant apps that we recommend. I've found instructionsfor creating the links to launch the Market but this assumes that you are the developer of the app in question and know the exact package name.

我正在创建一个移动网站,其中包含一个页面,人们可以从中下载我们推荐的相关应用程序。我发现的指示创建的链接,启动市场,但是这是假定你是有问题的应用程序的开发者和知道确切的包名。

Is there any way to get the package name, other than just contacting the developers and asking?

除了联系开发人员并询问之外,还有什么方法可以获得包名称?

Also, it turns out that those instructions don't really work for creating web hyperlinks. They only give you a URI to reference in a string of Java code in another Android app. Our site is in Drupal, so Java is not going to work.

此外,事实证明,这些说明并不能真正用于创建 Web 超链接。它们只为您提供一个 URI,以便在另一个 Android 应用程序中的 Java 代码字符串中进行引用。我们的站点在 Drupal 中,所以 Java 无法运行。

For the iPhone, I found easy instructionsfor getting the URL/link style I need from the iTunes store, so I'm looking for info like that.

对于 iPhone,我找到了从 iTunes 商店获取我需要的 URL/链接样式的简单说明,所以我正在寻找这样的信息。

回答by Chris

It depends where exactly you want to get the information from. You have a bunch of options:

这取决于您想要从何处获取信息。你有很多选择:

  • If you have a copy of the .apk, it's just a case of opening it as a zip file and looking at the AndroidManifest.xml file. The top level <manifest>element will have a packageattribute.
  • If you have the app installed on a device and can connect using adb, you can launch adb shelland execute pm list packages -f, which shows the package name for each installed apk.
  • If you just want to manually find a couple of package names, you can search for the app on http://www.cyrket.com/m/android/, and the package name is shown in the URL
  • You can also do it progmatically from an Android app using the PackageManager
  • 如果您有 .apk 的副本,只需将其作为 zip 文件打开并查看 AndroidManifest.xml 文件即可。顶级<manifest>元素将有一个package属性。
  • 如果您在设备上安装了该应用程序并且可以使用 连接adb,则可以启动adb shell并执行pm list packages -f,这会显示每个已安装 apk 的包名称。
  • 如果只想手动查找几个包名,可以在http://www.cyrket.com/m/android/上搜索app ,包名在URL中显示
  • 您还可以使用 Android 应用程序以编程方式执行此操作 PackageManager

Once you've got the package name, you simply link to market://search?q=pname:<package_name>or http://market.android.com/search?q=pname:<package_name>. Both will open the market on an Android device; the latter obviously has the potential to work on other hardware as well (it doesn't at the minute).

获得包名称后,只需链接到market://search?q=pname:<package_name>http://market.android.com/search?q=pname:<package_name>。两者都将在 Android 设备上打开市场;后者显然也有可能在其他硬件上工作(目前还没有)。

回答by accuya

Use aaptfrom the SDK like

aapt从 SDK 中使用,例如

aapt dump badging yourpkg.apk

This will print the package name together with other info.

这将打印包名称和其他信息。

the tools is located in
<sdk_home>/build-tools/android-<api_level>
or
<sdk_home>/platform-tools
or
<sdk_home>/platforms/android-<api_level>/tools

工具位于
<sdk_home>/build-tools/android-<api_level>

<sdk_home>/platform-tools

<sdk_home>/platforms/android-<api_level>/tools

Updated according to geniusburger's comment. Thanks!

根据Geniusburger的评论更新。谢谢!

回答by Brad Parks

The following bash script can be used to display the package and activity names in an apk, and launch the application by passing it an APK file.

以下 bash 脚本可用于显示 apk 中的包和活动名称,并通过向其传递 APK 文件来启动应用程序。

apk_start.sh

apk_start.sh

package=`aapt dump badging $* | grep package | awk '{print }' | sed s/name=//g | sed s/\'//g`
activity=`aapt dump badging $* | grep Activity | awk '{print }' | sed s/name=//g | sed s/\'//g`
echo
echo package : $package
echo activity: $activity
echo
echo Launching application on device....
echo
adb shell am start -n $package/$activity

Then to launch the application in the emulator, simply supply the APK filename like so:

然后要在模拟器中启动应用程序,只需像这样提供 APK 文件名:

apk_start.sh /tmp/MyApp.apk

Of course if you just want the package and activity name of the apk to be displayed, delete the last line of the script.

当然如果你只是想显示apk的包和活动名称,删除脚本的最后一行。

You can stop an application in the same way by using this script:

您可以使用以下脚本以相同的方式停止应用程序:

apk_stop.sh

apk_stop.sh

package=`aapt dump badging $* | grep package | awk '{print }' | sed s/name=//g | sed s/\'//g`
adb shell am force-stop $package

like so:

像这样:

apk_stop.sh /tmp/MyApp.apk

Important Note: aapt can be found here:

重要说明:aapt 可以在这里找到:

<android_sdk_home>/build-tools/android-<ver>/aapt

回答by Thejus Krishna

The following code will list them out:

以下代码将列出它们:

adb shell dumpsys package <packagename>

回答by Anonymous

Not sure if you still need this, but in http://www.appbrain.com/, you look up the app and the package name is in the url. For example: http://www.appbrain.com/app/fruit-ninja/com.halfbrick.fruitninjais the link for fruit ninja. Notice the bold

不确定您是否仍然需要它,但是在http://www.appbrain.com/ 中,您查找应用程序,并且包名称在 url 中。例如:http: //www.appbrain.com/app/fruit-ninja/com.halfbrick.fruitninja是水果忍者的链接。注意粗体

回答by Akil Adeshwar

Adding to the above answers: To find the package name of installed apps on any android device: Go to Storage/Android/data/< package-name >

添加到上述答案:要在任何 android 设备上查找已安装应用程序的包名称: 转到 Storage/Android/data/<package-name>

回答by R B

You can search the app online in the Google Play Store. When found, check the url, for example, https://play.google.com/store/apps/details?id=lutey.FTPServer&hl=en

您可以在 Google Play 商店在线搜索该应用程序。找到后查看url,例如https://play.google.com/store/apps/details?id=lutey.FTPServer&hl=en

The id parameter corresponds to the package name of the application. In the case of the url in the example, the package name is lutey.FTPServer.

id 参数对应于应用程序的包名。对于示例中的 url,包名称为 lutey.FTPServer。

回答by B.C.Kim

Here are easy way to get app's full package. we can use astro file manager app. You can get it on android market. Astro app manager show us app's full package.

这是获取应用程序完整包的简单方法。我们可以使用 astro 文件管理器应用程序。你可以在安卓市场上买到。Astro 应用程序管理器向我们展示了应用程序的完整包。

回答by Con

This is quite a difficult situation, you can get the package name from the apk file, but i assume you want to do it automatically.

这是一个相当困难的情况,您可以从 apk 文件中获取包名称,但我假设您想自动执行此操作。

AndroLib has the package names for lots of apps but you would have to parse it as there is no API that i could find. Theres a dev section that may have some tools to help you.

AndroLib 有很多应用程序的包名,但你必须解析它,因为我找不到 API。有一个开发部分可能有一些工具可以帮助您。

Good Luck

祝你好运

回答by bbsimonbb

Once you have the package name, as described Chris Smith's answer, you could/should use an intent url for the link. It's a special format URLthat will launch the package if the user has already installed it, or open the play store at the application's page if not...

一旦您获得了包名称,如Chris Smith's answer 所述,您可以/应该使用链接的意图 url。这是一个特殊格式的 URL,如果用户已经安装它,它将启动包,或者如果没有,则在应用程序页面打开 Play 商店......

intent://#Intent;package=qualified.package.name;end

The app needs to support this, with an activity tagged as browsable, but many will.

该应用程序需要支持这一点,将活动标记为可浏览,但很多人会这样做。