记住用户名和登录密码+虚拟机没有root权限解决办法
今日所学:
记住用户名和登录密码
用adb查看保存文件内容
遇到的问题:
用adb查看文件时,没有权限访问data文件
出现原因:google play虚拟机没有root权限
解决办法:
用google API的虚拟机
相关博客:adb shell中提示Permission denied - 简书
关于/system/bin/sh: su: not found的解决办法(安卓模拟器运行) - 程序员大本营
成果截图:

代码:
MainActivity.java
import androidx.appcompat.app.AppCompatActivity; import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText; public class MainActivity extends AppCompatActivity { private EditText mEtPhone;
private EditText mEtPasswd;
private CheckBox mPsd;
private String SP_PHONE="sp_phone";
private String SP_PASSWD="sp_passwd";
private SharedPreferences sharedPreferences;
private String SP_IS_REMEMBER="sp_is_remember";
private boolean isCheck=false;
private String TAG="MainActivity"; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initUI();
initData();
} private void initData() {
if(sharedPreferences==null){
sharedPreferences=getApplicationContext().getSharedPreferences("config", Context.MODE_PRIVATE);
}
mEtPhone.setText(sharedPreferences.getString(SP_PHONE,""));
mEtPasswd.setText(sharedPreferences.getString(SP_PASSWD,""));
isCheck=sharedPreferences.getBoolean(SP_IS_REMEMBER,false);
Log.i(TAG,"测试:"+isCheck);
mPsd.setChecked(isCheck);
} private void initUI() {
mEtPhone=findViewById(R.id.et_phone);
mEtPhone.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override
public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override
public void afterTextChanged(Editable s) {
if(isCheck){
if(sharedPreferences==null){
sharedPreferences=getApplicationContext().getSharedPreferences("config", Context.MODE_PRIVATE);
}
SharedPreferences.Editor edit=sharedPreferences.edit();
edit. putString(SP_PHONE,mEtPhone.getText().toString());
edit.commit();
} }
});
mEtPasswd=findViewById(R.id.et_passwd);
mEtPasswd.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override
public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override
public void afterTextChanged(Editable s) {
if(isCheck){
if(sharedPreferences==null){
sharedPreferences=getApplicationContext().getSharedPreferences("config", Context.MODE_PRIVATE);
}
SharedPreferences.Editor edit=sharedPreferences.edit();
edit.putString(SP_PASSWD,mEtPasswd.getText().toString());
edit.commit();
} }
});
mPsd=findViewById(R.id.cb_remember_psd);
mPsd.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Log.d(TAG,"状态为:"+isChecked);
isCheck=isChecked; if(sharedPreferences==null){
sharedPreferences=getApplicationContext().getSharedPreferences("config", Context.MODE_PRIVATE);
}
SharedPreferences.Editor edit=sharedPreferences.edit();
if(isChecked){
edit. putString(SP_PHONE,mEtPhone.getText().toString());
edit.putString(SP_PASSWD,mEtPasswd.getText().toString());
}
edit.putBoolean(SP_IS_REMEMBER,isChecked);
edit.commit();
}
}); }
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity"> <EditText
android:id="@+id/et_phone"
android:inputType="phone"
android:hint="电话"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/et_passwd"
android:inputType="textPassword"
android:hint="密码"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<CheckBox
android:id="@+id/cb_remember_psd"
android:text="记住密码"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button
android:text="登录"
android:layout_width="match_parent"
android:layout_height="wrap_content"/> </LinearLayout>
明日计划:
保存用户数据到数据库
记住用户名和登录密码+虚拟机没有root权限解决办法的更多相关文章
- javascript记住用户名和登录密码
javascript记住用户名和登录密码 下面主要通过代码给大家展示下javascript记住用户名和登录密码,具体代码内容请看下文. <script type="text/javas ...
- mysql Access denied for user \'root\'@\'localhost\'”解决办法总结,下面我们对常见的出现的一些错误代码进行分析并给出解决办法,有需要的朋友可参考一下。
mysql Access denied for user \'root\'@\'localhost\'”解决办法总结,下面我们对常见的出现的一些错误代码进行分析并给出解决办法,有需要的朋友可参考一下. ...
- "SQLServer无法打开用户默认数据库,登录失败,错误4064"的解决办法
"SQLServer无法打开用户默认数据库,登录失败,错误4064"的解决办法 1.检查登录密码 如果密码错误,修改数据库密码,用windows身份验证登录进去, (1)安全--登 ...
- Linux提示no crontab for root的解决办法
Linux提示no crontab for root的解决办法 安装crontab:yum install crontabs 说明:/sbin/service crond start //启动服务/s ...
- MySQL运行出错:无法连接驱动、无root访问权限解决办法
按照疯狂java讲义的13.3的程序,发现程序运行出错. 1.点开runConnMySql.cmd运行文件,出现如下结果: 2.用Editplus进行编译运行,如下结果: 报错定位到程序第18行,而第 ...
- VM出现该虚拟机正在使用中的提示,让获取所有权限解决办法
今天打开虚拟机正要学习,结果说是虚拟机似乎正在使用中,让我重新获取权限.解决办法:打开提示的配置文件的位置,将一个以.lck结尾的文件夹删除或者保存为另外的文件名称,再打开虚拟机就OK了.
- Ubuntu14.04 切换root账户su root失败解决办法
原因是需要备份一个vimrc,可是cp就提示Permission denied. su root就提示su: Authentication failure 解决办法: sudo passwd root ...
- Ubunt 使用Virtualbox虚拟机NAT无法上网解决办法
我的Ubuntu安装了一个Centos虚拟机,为了SSH和上外网的方便,使用了NAT+host Only方式,实现内网+外网,但是安装好的Centos不能连接外网,很是无语,只能Google了-- 解 ...
- ssh远程登录出现Host key verification failed.解决办法
今天通过ssh和域名连接主机: IcarusdeMacBook-Pro:~ icarus$ ssh root@icarusyu.me 出现了如下错误: @@@@@@@@@@@@@@@@@@@@@@@@ ...
随机推荐
- LeetCode-055-跳跃游戏
跳跃游戏 题目描述:给定一个非负整数数组 nums ,你最初位于数组的 第一个下标 . 数组中的每个元素代表你在该位置可以跳跃的最大长度. 判断你是否能够到达最后一个下标. 示例说明请见LeetCod ...
- Spring注解简析
JAVA 元注解 @Documented @Inherited @Retention @Target @Repeatable @Native 在java.lang.annotation包下,除了@Na ...
- 二进制部署1.23.4版本k8s集群-2-安装DNS服务
2.安装DNS服务 为什么要安装bind9? K8S中,使用Ingress进行7层流量调度,需要使用域名,进行7层调度. 以前使用绑定host的方法,来进行域名和IP地址的解析. 在K8S里,没有好的 ...
- tp5手机号验证码发送及验证
原文链接:https://blog.csdn.net/weixin_43389208/article/details/119153323 为什么使用短信: 场景:通常在使用手机号注册时需要发送短信验证 ...
- kkFileView部署到windows服务出现问题解决
1.部署之后执行出现api-ms-win-crt-runtime-l1-1-0.dll丢失的办法 微软官网下载vc_redist.x64.exe vc_redist.x86.exe 64位的操作系统需 ...
- vscode使用python虚拟环境
vscode使用python虚拟环境 创建好虚拟环境之后,在vscode中配置使用python的虚拟环境. 首先打开设置,然后搜索python venv, 在python: Venv Path中设置为 ...
- docker 部署mysql tomcat时 在root@localhost~下——-——docker exec -it 容器名 /bin/bash 报错
在docker部署mysql时 报错 找不到 容器不自动启动 , docker start 容器名 也没有效果 多次尝试发现 原因是创建容器时在 下面创建的 更改为下创建 问题解决
- JavaWeb 02_servlet基础
1. servlet是什么?作用? 1) Servlet 是Sun公司制定的一套技术标准,包含与Web应用相关的一系列接口,是Web应用实现方式的宏观解决方案I而具体的Servlet容器负责提供标准的 ...
- Linux配置FTP(vsftpd)服务和无法上传下载问题解决
vsftpd的配置说明 ftp的配置文件主要有三个,位于/etc/vsftpd/目录下,分别是: ftpusers 该文件用来指定那些用户不能访问ftp服务器. user_list 该文件用来指示的默 ...
- springcloud学习01-用intellij idea搭建Eureka服务
0.配置intellij idea工具:https://www.cnblogs.com/wang-liang-blogs/p/12060702.html 1.使用maven构建工具构建主工程项目. 1 ...