admin管理员组文章数量:1662623
最近有一个需求,产品经理按照IOS发布新版后在appstore评论或者评分功能设计的,让Android跳转到本机应用商店中本应用的详情页。
上网查了一些资料,实现步骤如下:
弹出对话框:
/**
* 应用评价对话框
*
* @param activity 上下文
* @return 对话框
*/
public static Dialog showAppSuggestDialog(Activity activity) {
Dialog dialog = new Dialog(activity, R.style.MyDialog);
View contentView = View.inflate(activity, R.layout.dialog_version_suggest, null);
dialog.setContentView(contentView);
dialog.setCanceledOnTouchOutside(true);
dialog.show();
ImageView update_close = contentView.findViewById(R.id.update_close);
TextView tv_say_bad = contentView.findViewById(R.id.tv_say_bad);
TextView tv_say_good = contentView.findViewById(R.id.tv_say_good);
update_close.setOnClickListener(view -> dialog.dismiss());
tv_say_bad.setOnClickListener(view -> {
dialog.dismiss();
toMarket(activity);
});
tv_say_good.setOnClickListener(view -> {
dialog.dismiss();
toMarket(activity);
});
return dialog;
}
MyDialog为对话框样式:
<style name="MyDialog" parent="@android:style/Theme.Dialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:background">@color/transparent</item>
</style>
点击对话框按钮获取跳转意图:
/**
* 获取跳转意图
*
* @param context 上下文
* @return 意图
*/
public static Intent getIntent(Context context) {
StringBuilder localStringBuilder = new StringBuilder().append("market://details?id=");
String str = context.getPackageName();
localStringBuilder.append(str);
Uri localUri = Uri.parse(localStringBuilder.toString());
return new Intent("android.intent.action.VIEW", localUri);
}
判断是否有应用商店:
/**
* 判断是否有应用市场
*
* @param context 上下文
* @param marketIntent 跳转意图
* @return 是否有应用市场true/false
*/
public static boolean judge(Context context, Intent marketIntent) {
List<ResolveInfo> localList = context.getPackageManager().queryIntentActivities(marketIntent, PackageManager.GET_RESOLVED_FILTER);
if ((localList != null) && (localList.size() > 0)) {
return false;
} else {
return true;
}
}
跳转到应用详情:
/**
* 跳转到应用详情页
*
* @param activity 上下文
*/
private static void toMarket(Activity activity) {
Intent intent = getIntent(activity);
boolean b = judge(activity, intent);
if (!b) {
try {
activity.startActivity(intent);
} catch (ActivityNotFoundException e) {
MyToast.showToast(Constants.ERROR_NO_MARKET);
}
} else {
MyToast.showToast(Constants.ERROR_NO_MARKET);
}
}
最终实现结果:
评论和评分,在Android上只能进入详情页,由用户点击评价进到评分和评论的页面,所以跳转逻辑一样;
进行跳转只能跳转到本机已安装应用,所以进入的是本机预装的应用商店。如果本机应用商店中没有收录自己的应用,跳转后搜索不到应用包名。ps:然而上线前这个功能被pass掉了。
版权声明:本文标题:Android跳转到应用商店详情页面 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dongtai/1729958755a1217431.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论