最近有一个需求,产品经理按照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为对话框样式:

点击对话框按钮获取跳转意图:

 /**     * 获取跳转意图     *     * @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 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掉了。

更多相关文章

  1. android体系介绍
  2. Android开发者指南(10) —— Android(安卓)API Levels
  3. android点滴(8) -- android应用程序的生命周期
  4. Mac配置Android开发环境变量及工具安装图
  5. Android(安卓)对话框(Dialog)大全 建立你自己的对话框
  6. Android系统层次结构及分析
  7. Android中Dialog的使用
  8. Android开发指南(36) —— Search
  9. Android引路蜂地图开发示例:第一个地图应用

随机推荐

  1. Android(安卓)实现显示文字的Gallery
  2. android 界面中加入密码框
  3. Android(安卓)网站资源收集大全
  4. Android给TextView添加点击事件的实现方
  5. Android各种Layout用到的一些重要的属性
  6. andriod RelativeLayout布局居中
  7. android 相关的网站
  8. android logo:内核、android开机动画
  9. Android修改Gallery页面布局
  10. 3.EditText