SharedPreferences 保存到本地全局调用

时间:2022-04-04 05:36:06
 private void readSharedPreferences() {
SharedPreferences sp = this.getSharedPreferences(
"UUIDnumber", Context.MODE_PRIVATE);
String name = sp.getString("uuid_number", "无值");
Log.d("存储到本地的用户名", name);
}

// 写入记录到本地
private void wrtieSharedPreferences() {
SharedPreferences shared = this.getSharedPreferences(
"UUIDnumber", Context.MODE_PRIVATE);
SharedPreferences.Editor edit = shared.edit();
s = UUID.randomUUID().toString().replace("-", "");
edit.putString("uuid_number", s);
// 提交
edit.commit();
}

case R.id.open:
readSharedPreferences();
wrtieSharedPreferences();
Log.e(TAG, "onClick: " + s);
Intent i = new Intent(OpenCreditActivity.this, FaceOcrActivity.class);
startActivity(i);
break;



 SharedPreferences sp = getActivity().getSharedPreferences(
"UUIDnumber", Context.MODE_PRIVATE);
String name = sp.getString("uuid_number", "无值");
Log.d("存储到本地的用户名", name);
String key = "对比照" + name + ".JPEG";