在华为应用商店中打开您的应用程序类似于打开Google Play Store:
华为应用商店:
market://
或 appmarket://
com.huawei.appmarket
Google Play Store:
market://
com.android.vending
这是针对华为应用商店的代码片段:
private void startHuaweiAppGallery() {
Uri detailsUri = Uri.parse("market://details?id=" + getPackageName());
Intent intent = new Intent(Intent.ACTION_VIEW, detailsUri);
List<ResolveInfo> otherApps =
getPackageManager().queryIntentActivities(intent, 0);
for (ResolveInfo app : otherApps) {
String packageName = app.activityInfo.applicationInfo.packageName;
if (!packageName.equals("com.huawei.appmarket")) {
continue;
}
intent.addFlags(
Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED |
Intent.FLAG_ACTIVITY_CLEAR_TOP
);
intent.setComponent(new ComponentName(packageName, app.activityInfo.name));
startActivity(intent);
return;
}
//Huawei App Gallery N/A. Open app link in browser.
//Huawei App ID can be found in the Huawei developer console
final string huaweiAppID = "100864605";
//ex. https://appgallery.cloud.huawei.com/marketshare/app/C100864605
Uri appUri = Uri.parse(
"https://appgallery.cloud.huawei.com/marketshare/app/C" + huaweiAppID
);
intent = new Intent(Intent.ACTION_VIEW, appUri);
startActivity(intent);
}
以下是Google Play的代码片段:
private void startGooglePlay() {
Uri detailsUri = Uri.parse("market://details?id=" + getPackageName());
Intent intent = new Intent(Intent.ACTION_VIEW, detailsUri);
List<ResolveInfo> otherApps =
getPackageManager().queryIntentActivities(intent, 0);
for (ResolveInfo app : otherApps) {
String packageName = app.activityInfo.applicationInfo.packageName;
if (!packageName.equals("com.android.vending")) {
continue;
}
intent.addFlags(
Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED |
Intent.FLAG_ACTIVITY_CLEAR_TOP
);
intent.setComponent(new ComponentName(packageName, app.activityInfo.name));
startActivity(intent);
return;
}
//Google Play N/A. Open app link in browser.
Uri appUri = Uri.parse(
"https://play.google.com/store/apps/details?id=" + getPackageName()
);
intent = new Intent(Intent.ACTION_VIEW, appUri);
startActivity(intent);
}
这里是代码片段,允许用户在设备上选择任何可用店铺:
private void startAnyStore() {
Uri detailsUri = Uri.parse("market://details?id=" + getPackageName());
Intent intent = new Intent(Intent.ACTION_VIEW, detailsUri);
intent.addFlags(
Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED |
Intent.FLAG_ACTIVITY_CLEAR_TOP
);
startActivity(intent);
}
我同意@Pierre的看法
但我也认为你可以通过链接解决活动问题
https://appgallery8.huawei.com/#/app/C<HUAWEI_APP_ID>
或者
https://appgallery.cloud.huawei.com/uowap/index.html#/detailApp/C<HUAWEI_APP_ID>?appId=C<HUAWEI_APP_ID>
例如,https://appgallery.cloud.huawei.com/uowap/index.html#/detailApp/C101652909?appId=C101652909
HUAWEI_APP_ID
前面的那个 C
。 - Milorehttps://appgallery.huawei.com/#/app/C27162
您可以将appid替换为您自己的appid。
https://appgallery.cloud.huawei.com/appDetail?pkgName=com.huawei.appmarket
你可以将包名替换为自己的包名。华为应用商城现在似乎可以使用与Google Play相同的URI打开详细页面:market://details?id=<applicationId>
我刚刚在AppGallery v11.1.2.304 上尝试了一个在两个商城中都存在的applicationId:
adb shell am start -a "android.intent.action.VIEW" -d "market://details?id=busu.blackscreenbatterysaver"
appmarket://
模式的深度链接,就像Pierre在接受的答案中所指示的那样。对我来说,AppGallery的https链接并没有像应用链接一样运行,我仍然会得到歧义对话框(选择华为浏览器处理意图的应用程序列表后,它最终将启动设备上的AppGallery本机应用程序,并显示您的应用程序详细信息)- 尝试 adb shell am start -a“android.intent.action.VIEW”-d“https://appgallery.huawei.com/#/app/C103639735”
。 - Adi Bmarket://
模式的通用解决方案(而不是每个商店都有不同的深度链接),因为当你编写一个希望跨平台的应用程序时,这更加方便。 - Adi Bpublic void reviewApp(String packageName){
try {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("appmarket://details?id=" + packageName));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
} catch (ActivityNotFoundException anfe) {
Toast.makeText(this, "Huawei AppGallery not found!", Toast.LENGTH_SHORT).show();
}
}
然后从您的活动中调用它:
reviewApp(this.getPackageName());
或者:
reviewApp("com.myapp.android");
通过包名启动Play Store/AppGallery。
private boolean openInStore(String uri){
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_CLEAR_TOP);
try {
startActivity(Intent.createChooser(intent,getString(R.string.open_with)));
return true;
} catch (ActivityNotFoundException anfe) {
return false;
}
}
private void startOpenInStore() {
String playStoreScheme = "market://details?id=", huaweiScheme = "appmarket://details?id=";
if (!openInStore(playStoreScheme+getPackageName())) {
if (!openInStore(huaweiScheme + getPackageName())) {
openInStore("https://play.google.com/store/apps/details?id=" + getPackageName());
}
}
}
我认为最短且最简单的方法是运行这个简单链接:https://appgallery.cloud.huawei.com/ag/n/app/<YOUR_APP_ID>
。
无需配置任何内容,华为将自动处理其余事项。
如何获取“YOUR_APP_ID”?
C5683
以下是直接启动应用商店的方法:
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri.Builder uriBuilder = Uri.parse("https://appgallery.cloud.huawei.com/ag").buildUpon();
intent.setData(uriBuilder.build());
intent.setPackage("com.huawei.appmarket");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
华为应用商店
的代码才能打开你的应用程序。这是唯一的方法。 - Vladyslav Matviienko