安卓中QQ登陆源代码
安卓中QQ登陆
一种是流的方式,一种是声明一个共享参数sharedpreference
第一种方法:
第一步:将QQ头像粘贴到drawable—hdpi中
第二步:在xml布局文件中编辑页面布局(ImageView,EditText,CheckBox,Button)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
tools:context=".MainActivity" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/qq"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入QQ号码"
android:id="@+id/et_qqnumber"/>
<EditText
android:id="@+id/et_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入密码"
android:inputType="textPassword"/>
<CheckBox
android:id="@+id/cb_remember"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="记住用户和密码"/>
<Button
android:onClick="login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="登陆"/>
</LinearLayout>
第三步:在src中编辑逻辑
public class MainActivity extends Activity {
private EditText et_qqnumber;
private EditText et_password;
private CheckBox cb_remember;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//寻找这些控件
et_qqnumber = (EditText) findViewById(R.id.et_qqnumber);
et_password = (EditText) findViewById(R.id.et_password);
cb_remember = (CheckBox) findViewById(R.id.cb_remember);
restoreInfo();
}
/**
* 登陆按钮的点击事件
* @param view
*/
public void login(View view){
String qq = et_qqnumber.getText().toString().trim();
String password = et_password.getText().toString().trim();
if(TextUtils.isEmpty(qq)||TextUtils.isEmpty(password)){
Toast.makeText(this, "用户名和密码不能为空", 0).show();
return;
}else{
//判断是否需要记录用户名和密码
if(cb_remember.isChecked()){//被选中状态,需要记录用户名和密码
try {
File file = new File(this.getFilesDir(),"info.txt");
FileOutputStream fos = new FileOutputStream(file);
//10000##123456
String info = qq +"##"+password;
fos.write(info.getBytes());
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
//登陆操作的. 模拟登陆,数据应该提交给服务器 由服务器比较是否正确
if("10000".equals(qq)&&"123456".equals(password)){
Toast.makeText(this, "登陆成功", 0).show();
}else{
Toast.makeText(this, "登陆失败", 0).show();
}
}
}
/**
* 根据原来保存的文件信息,把qq号码和密码信息回显到界面
* getFilesDir()//获取应用程序files目录 /data/data/包名/files/ 文件夹
*/
public void restoreInfo(){
File file = new File(this.getFilesDir(),"info.txt");
if(file.exists()&&file.length()>0){
try {
FileInputStream fis = new FileInputStream(file);
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
//10000##123456
String info = br.readLine();
String qq = info.split("##")[0];
String pwd = info.split("##")[1];
et_qqnumber.setText(qq);
et_password.setText(pwd);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
第二种方法:
public class MainActivity extends Activity {
private EditText et_qqnumber;
private EditText et_password;
private CheckBox cb_remember;
/**
* 1. 声明一个共享参数(存储数据方便的api)
*/
private SharedPreferences sp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//2. 通过上下文得到一个共享参数的实例对象
sp = this.getSharedPreferences("config", 0);
//类似 File f = new File("config");
//寻找这些控件
et_qqnumber = (EditText) findViewById(R.id.et_qqnumber);
et_password = (EditText) findViewById(R.id.et_password);
cb_remember = (CheckBox) findViewById(R.id.cb_remember);
restoreInfo();
}
/**
* 登陆按钮的点击事件
* @param view
*/
public void login(View view){
String qq = et_qqnumber.getText().toString().trim();
String password = et_password.getText().toString().trim();
if(TextUtils.isEmpty(qq)||TextUtils.isEmpty(password)){
Toast.makeText(this, "用户名和密码不能为空", 0).show();
return;
}else{
//判断是否需要记录用户名和密码
if(cb_remember.isChecked()){//被选中状态,需要记录用户名和密码
//TODO:记录密码
Editor editor = sp.edit();
editor.putString("qq", qq);
editor.putString("password", password);
editor.commit();//提交数据. 类似关闭流,事务
}
//登陆操作的. 模拟登陆,数据应该提交给服务器 由服务器比较是否正确
if("10000".equals(qq)&&"123456".equals(password)){
Toast.makeText(this, "登陆成功", 0).show();
}else{
Toast.makeText(this, "登陆失败", 0).show();
}
}
}
/**
* 根据原来保存的文件信息,把qq号码和密码信息回显到界面
*/
public void restoreInfo(){
//TODO:读取密码
String qq = sp.getString("qq", "");
String password = sp.getString("password", "");
et_qqnumber.setText(qq);
et_password.setText(password);
}
}
this.getFilesDir() 获取文件的路径 getFilesDir()//获取应用程序files目录 /data/data/包名/files/ 文件夹
file.exists()判断这个文件是否存在
file.length()>0判断里面是否有数据
cb_remember.isChecked() checkBox 单选框 打上对号就代表选中了true,没打上对号是不是就代表没有选中false
br.readLine();读一行
String qq = info.split("##")[0];分成一个数组,长度为2,第一个角标放置的东西就是qq号码,第二个角标放置的就是密码
String pwd = info.split("##")[1];
安卓中QQ登陆源代码相关推荐
- qqp2011java_腾讯开放平台中实现QQ登陆的功能
昨天为自己的网站实现了QQ登陆的功能,虽然,没有进行绑定,但是在技术层面上来说,已经了解了一点腾讯开放平台的协议. 具体什么是OAUTH,请您GG一下吧... 关于腾讯的开放平台,最主要的就是参数一定 ...
- php仿qq登录界面安卓,Android_Android仿QQ登陆窗口实现原理,今天根据腾讯qq,我们做一个 - phpStudy...
Android仿QQ登陆窗口实现原理 今天根据腾讯qq,我们做一个练习,来学习如何制作一个漂亮的布局.首先看一下官方图片 还是一个启动画面,之后进入登录页面,导航页面就不介绍了,大家可以参考微信的导航 ...
- 基于安卓开发的QQ登陆页面,实现登陆注册内容
基于安卓开发的QQ登陆页面,实现登陆注册内容(一) QQ登陆注册 首先对于QQ登陆注册而言,先控制好布局,和对控件的使用: 页面效果如下: 部分代码: <TextViewandroid:layo ...
- Android开发之使用SharedPreferences实现QQ登陆的选项框记忆功能(源代码分享)
本系列文章由@林泓成出品,转载请注明出处. 根据上篇博客讲的SharedPreferences的简单实现,我们来实现下QQ登陆的时候用户名自动显示以及勾选是否记忆用户名和隐身登陆的功能,通过实例来展现 ...
- 计算机考证qq登陆,一开计算机就登陆QQ,怎样设置?
2014-11-14 qq登陆保护怎么设置 求 首先,我们打开自己的QQ,然后切换到QQ的功能主菜单页面,选择"我的QQ中心". 然后我们在打开的页面中,选择"账号&qu ...
- QQ互联OAuth2.0 .NET SDK 发布以及网站QQ登陆示例代码(转)
OAuth: OAuth(开放授权)是一个开放标准,允许用户授权第三方网站访问他们存储在另外的服务提供者上的信息,而不需要将用户名和密码提供给第三方网站或分享他们数据的所有内容. QQ登录OAuth2 ...
- 安卓中如何实现滑动导航
2019独角兽企业重金招聘Python工程师标准>>> 导航是移动应用最重要的方面之一,对用户体验是良好还是糟糕起着至关重要的作用.好的导航可以让一款应用更加易用并且让用户快速上手. ...
- QQ互联OAuth2.0 .NET SDK 发布以及网站QQ登陆示例代码
OAuth: OAuth(开放授权)是一个开放标准,允许用户授权第三方网站访问他们存储在另外的服务提供者上的信息,而不需要将用户名和密码提供给第三方网站或分享他们数据的所有内容. QQ登录OAuth2 ...
- android修改尾巴软件,安卓手机QQ自定义尾巴编辑教程
想必各位机友都很羡慕苹果手机或ipad登录QQ会显示来自QQfor iPhone的尾巴吧?那就是,当自己或者别人用手机登入QQ,并开始聊天的时候,在聊天内容的下方会出现这样一行文字:"(来自 ...
最新文章
- java try catch_Java中关于try、catch、finally中的细节分析
- 小米平板2更新bios版本_【军团战争5.25】新版本更新预告第一弹,2级兵3次升级!...
- iTextSharp应用,生成pdf
- python怎么输入一个数字并调用_Python3 实例(一)
- 《软件项目管理(第二版)》第 10 章——项目收尾 重点部分总结
- java的map 使用string数组多了双引号_奥奥奥利给!!!再也不怕面试官问我String源码了!来吧...
- Mysql 函数入门
- springcloud 系列教程一:微服务与网站架构演变过程
- python求奇数的乘积_Python中的推导式使用详解
- idea中plugins配置
- js操作符类型转换大全
- 全局配置_中兴天机配置公布:智汇屏+全局黑暗模式
- 宝塔控制面板配置Nginx 安全证书
- 2021数据安全与个人信息保护技术白皮书
- 【神经网络解耦】基于matlab的神经网络解耦系统仿真
- SAP扫盲系列之一:什么是SAP系统和应用服务器
- 用python告诉你,韦小宝跟他七个老婆哪个最亲?
- Mac打不开别人的.one文件
- Vlan(虚拟局域网配置)
- 2012年5月SAT香港真题解析