Android 如何检查用户是否输入了促销代码?

Android 如何检查用户是否输入了促销代码?,android,in-app-purchase,Android,In App Purchase,我有一个android应用程序,你只需输入promocode就可以得到完整的版本。但如何在其他活动中检查是否已输入?这是我的代码: AlertDialog.Builder alert = new AlertDialog.Builder(Browser.this); alert.setTitle("Enter your promocode."); final View input = L

我有一个android应用程序,你只需输入promocode就可以得到完整的版本。但如何在其他活动中检查是否已输入?这是我的代码:

AlertDialog.Builder alert = new AlertDialog.Builder(Browser.this);
                            alert.setTitle("Enter your promocode.");
                            final View input = LayoutInflater.from(Browser.this).inflate(R.layout.edittext, null);
                            alert.setView(input);
                            final EditText edit = (EditText) input.findViewById(R.id.edit);
                            alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int whichButton) {
                                    if (edit.getText().toString().equalsIgnoreCase("TheSecretcode")) {
                                        isPremium = true;
                                    } else {
                                        isPremium = false;
                                    }
                                }
                            });
                            alert.show();
                            break;
这是第二个活动的代码。我想它只是没有更新SharedPref

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.image_view_layout);
    Uri uri = getIntent() != null ? getIntent().getData() : null;
    final SharedPreferences premiumSettings = getSharedPreferences("PREMIUM", Context.MODE_PRIVATE);
    final boolean isPremium = premiumSettings.getBoolean("isPremium", false);
    if(isPremium) {
        ImageView img = (ImageView) findViewById(R.id.imageView);
        img.setImageURI(uri);
    }
    else {
        AlertDialog.Builder builder = new AlertDialog.Builder(ImageViewer.this);
        builder.setTitle("Error");
        builder.setMessage("You are not premium user. Please enter the promocode or buy the full version");
        builder.setIcon(R.drawable.holo_dark_action_info);
        builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                finish();
            }
        });
        AlertDialog dialog = builder.create();
        dialog.show();
    }
}
}使用

然后在另一个活动中,检索您的首选项:

final SharedPreferences premiumSettings = getSharedPreferences("PREMIUM", Context.MODE_PRIVATE); // The name is the same as previously
final boolean isPremium = premiumSettings.getBoolean("isPremium", false); // false is default value
final SharedPreferences premiumSettings = getSharedPreferences("PREMIUM", Context.MODE_PRIVATE); // The name is the same as previously
final boolean isPremium = premiumSettings.getBoolean("isPremium", false); // false is default value