更新时间:2023-11-30 22:33:58
我不确定您的应用程序是否正常运行,但据我了解:用户可以在未经身份验证的情况下使用您的应用程序.但是,您希望未经身份验证的用户只能访问有限数量的功能.
I'm not sure about the flow of your app but from what I understand: Users can use your app without being authenticated. However, you want unauthenticated users to have access to only a limited number of features.
您在评论中提到,无论以前使用什么应用程序,用户都必须在每次新安装的应用程序中验证其电话号码.因此,您可以像这样使用SharedPreferences来发挥自己的优势:
You mentioned in the comments that users are required to verify their phone number on every fresh install of the app regardless of previous use. Therefore, you can use SharedPreferences to your advantage like this:
// create a SharedPreferences object and reference it with "AUTH_STATUS"
SharedPreferences sharedPreferences = getSharedPreferences("AUTH_STATUS", Context.MODE_PRIVATE);
// create an editor object from your sharedpreferences object
SharedPreferences.Editor editor = sharedPreferences.edit();
// save your boolean value to a reference called "status"
editor.putBoolean("status", true);
// save changes
editor.apply();
要检索保存的布尔值,可以执行以下操作:
To retrieve a saved boolean value, you can do something like this:
// create a SharedPreferences object and reference it with "AUTH_STATUS"
SharedPreferences sharedPreferences = getSharedPreferences("AUTH_STATUS", Context.MODE_PRIVATE);
// get saved boolean value, default value should be false
boolean ab = sharedPreferences.getBoolean("status", false);
要删除/重置SharedPreferences布尔值,只需将布尔值设置为false即可,如下所示:
To delete/reset the SharedPreferences boolean value, simply set the boolean value to false as shown below:
// create a SharedPreferences object and reference it with "AUTH_STATUS"
SharedPreferences sharedPreferences = getSharedPreferences("AUTH_STATUS", Context.MODE_PRIVATE);
// create an editor object from your sharedpreferences object
SharedPreferences.Editor editor = sharedPreferences.edit();
// save your boolean value to a reference called "status"
editor.putBoolean("status", false);
// save changes
editor.apply();