首页 > 解决方案 > 调用 onBackPressed 时如何设置链接

问题描述

我是新的 Android 开发人员,我想在调用 onBackPressed 时为我的第三个按钮设置链接。其余 2 人工作正常。但我想,当点击“更多应用”时,它会重定向到 Google Play 商店。我怎么做?请帮助我专家开发人员。

@Override
    public void onBackPressed() {
        AlertDialog.Builder alert = new AlertDialog.Builder(this);
        alert.setIcon(R.drawable.ic_close);
        alert.setCancelable(false);
        alert.setNeutralButton("More Apps", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

            }
        });
        alert.setTitle("Listview Application");
        alert.setMessage("Do you want to close?");
        alert.setNegativeButton("Yes", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });
        alert.setPositiveButton("No", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });

        alert.show();
    }

标签: android

解决方案


调用此方法。

public void openMoreApps(String playStoreUrl) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse(playStoreUrl));
    startActivity(intent);
}

推荐阅读