1
У меня есть приложение для Android, в котором вы можете просто ввести promocode, чтобы получить полную версию. Но как сделать в других действиях проверить, введено это или нет? Это мой код:Как проверить, введен ли пользователь 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;
это код для второго вида деятельности. Я думаю, что он просто не обновил SharedPrefs.
@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();
}
}
}