问题
I know that is possible to open my app (based on package name) in Google Play Store, but how to do same in Huawei AppGallery?
回答1:
Opening your app in the Huawei App Gallery is similar to opening Google Play Store.
Here is a snippet for the Huawei App Gallery:
private void startHuaweiAppGallery() {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("appmarket://details?id=" + getPackageName()));
List<ResolveInfo> otherApps = getPackageManager().queryIntentActivities(intent, 0);
for (ResolveInfo app : otherApps) {
if (app.activityInfo.applicationInfo.packageName.equals("com.huawei.appmarket")) {
ComponentName psComponent = new ComponentName(app.activityInfo.applicationInfo.packageName, app.activityInfo.name);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setComponent(psComponent);
startActivity(intent);
break;
}
}
}
Here is the snippet for Google Play:
private void startGooglePlay() {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + getPackageName()));
List<ResolveInfo> otherApps = getPackageManager().queryIntentActivities(intent, 0);
boolean psFound = false;
for (ResolveInfo app : otherApps) {
if (app.activityInfo.applicationInfo.packageName.equals("com.android.vending")) {
ComponentName psComponent = new ComponentName(app.activityInfo.applicationInfo.packageName, app.activityInfo.name);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setComponent(psComponent);
startActivity(intent);
psFound = true;
break;
}
}
if (!psFound) {
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + getPackageName()));
startActivity(intent);
}
}
As you can see in the Google Snippet, if the Play app is not found, then open the url directly in the browser of the client. Unfortunately I do not know of an online store for Huawei ... yet of course..
In my case, my app is hosted in both stores, so I just copied the google play browser part into the Huawei snippet as well.
回答2:
A simple way to open app in Huawei App Gallery store:
public 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();
}
}
then call it from your activity:
reviewApp(this.getPackageName());
or:
reviewApp("com.myapp.android");
回答3:
Ok bro. You can use the package name. com.huawei.appmarket and use Intent. There is a similar question here. Launch an application from another application on Android
Good luck for whatever you doing 😊
来源:https://stackoverflow.com/questions/53705612/how-to-open-the-huawei-appgallery-directly