gpt4 book ai didi

android - PackageManager.getInstallerPackageName() 可以告诉我我的应用是从亚马逊应用商店安装的吗?

转载 作者:IT王子 更新时间:2023-10-28 23:35:06 44 4
gpt4 key购买 nike

我计划在亚马逊应用商店和 Google Play 上发布我的应用程序,并且我的应用程序中的某些内容需要根据应用程序是否从亚马逊应用程序商店安装而略有不同。如果我正确理解了 PackageManager.getInstallerPackageName(String packageName) 方法,它会告诉我安装我的应用程序的应用程序的名称。正确的?如果是这样,如果我的应用 是从亚马逊应用商店安装的,是否有人知道此方法返回的值是多少?如果没有,是否有人知道我可以使用其他方法来确定我的应用程序是否是从亚马逊应用商店安装的?

Note: I am aware of other questions on Stack Overflow which have been answered alluding to the usage of PackageManager.getInstallerPackageName(String packageName) to determine the name of the application that installed my app. However, searching Stack Overflow and elsewhere, I have not been able to determine what the value returned by PackageManager.getInstallerPackageName(String packageName) would be in case the app was installed from the Amazon app store.

最佳答案

由于三星没有实现 PackageManager.getInstallerPackageName(),它仍然返回 null。所以使用 PackageManager.getInstalledPackages() 获取所有包并搜索 samsungapp 包名“com.sec.android.app.samsungapps”。

商店:

null - developer
com.android.vending - google play
com.amazon.venezia - amazon app
com.sec.android.app.samsungapps - samsung app store

代码:

// lets start with google play store link
String link = "https://play.google.com/store/apps/details?id=com.hellothupten.capital2countryquiz";

//find out the installer for your app package name.
String installer = getPackageManager().getInstallerPackageName(
"com.hellothupten.capital2countryquiz");

if (installer == null) {
List<PackageInfo> installedPackages = getPackageManager()
.getInstalledPackages(PackageManager.GET_ACTIVITIES);
for (PackageInfo p : installedPackages) {
if (p.packageName.contains("samsungapps")) {
// change to samsung app store link
link = "http://apps.samsung.com/mars/topApps/topAppsDetail.as?productId=000000840239";
break;
}
}
} else if (installer.contains("amazon")) {
// change to amazon app store link
link = "amzn://apps/android?p=com.hellothupten.capital2countryquiz";
} else if (installer.contains("samsung")) {
// change to samsung app store link. This does not
// exist..but who knows samsung may implement
// getInstallerPackageName in future, I assume it will
// contain a word samsung in its package name.
link = "http://apps.samsung.com/mars/topApps/topAppsDetail.as?productId=000000840239";

}

使用链接变量作为商店链接。

更新:

samsungapps://ProductDetail/com.sec.chaton

三星:http://developer.samsung.com/android/technical-docs/Samsung-Apps-Deeplink-Guide

关于android - PackageManager.getInstallerPackageName() 可以告诉我我的应用是从亚马逊应用商店安装的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13289748/

44 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com