Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to develop and save QQ password function in Android

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

In this article Xiaobian for you to introduce in detail "Android how to develop and save QQ password function", the content is detailed, the steps are clear, and the details are handled properly. I hope that this "Android how to develop and save QQ password function" article can help you solve your doubts.

Technical points:

Save data using file storage

Implementation steps:

Design and implementation of ① user Interface

Design and implementation of ② tool Class (FileSaveQQjava)

Design and implementation of ③ Interface Logic Code

For the page layout, please see the simple QQ login page for Android development.

MainActivity.java Code:

Package com.example.saverqq;import androidx.appcompat.app.AppCompatActivity;import android.os.Bundle;import android.text.TextUtils;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.Toast;import java.util.Map;public class MainActivity extends AppCompatActivity implements View.OnClickListener {private Button etLogin; private EditText etPassword; private EditText etNumber; @ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState) SetContentView (R.layout.activity_main); / / initialize view initView (); / / echo data if the user has already saved it: Map userInfo = FileSaveQQ.getUserInfo (this); if (userInfographic null) {etNumber.setText (userInfo.get ("number")); etPassword.setText (userInfo.get ("password")) } private void initView () {/ / initialize control etNumber = (EditText) findViewById (R.id.et_number); etPassword = (EditText) findViewById (R.id.et_password); etLogin = (Button) findViewById (R.id.btn_login); / / set button click event etLogin.setOnClickListener (this) } @ Override public void onClick (View view) {/ / Click the button to get the account password String number = etNumber.getText () .toString () .trim (); String password = etPassword.getText () .toString () .trim (); if (TextUtils.isEmpty (number)) {Toast.makeText (this, "Please enter QQ account", Toast.LENGTH_LONG) .show (); return } if (TextUtils.isEmpty (password)) {Toast.makeText (this, "Please enter QQ password", Toast.LENGTH_LONG) .show (); return;} Toast.makeText (this, "login successful", Toast.LENGTH_LONG). Show (); / / Save user information boolean isSaveSucess = FileSaveQQ.saveUserInfo (this, number, password) If (isSaveSucess) {Toast.makeText (this, "Save successfully", Toast.LENGTH_LONG). Show ();} else {Toast.makeText (this, "Save failed", Toast.LENGTH_LONG). Show ();}

FileSaveQQ.java file code:

Package com.example.saverqq;import android.content.Context;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.util.HashMap;import java.util.Map Public class FileSaveQQ {/ / Save user information public static boolean saveUserInfo (Context context, String number, String password) {try {/ / get file output stream FileOutputStream fos = context.openFileOutput ("data.txt", context.MODE_PRIVATE) through upstream and downstream; / / write data to file fos.write ((number + ":" + password) .getBytes ()) Fos.close (); return true;} catch (Exception e) {e.printStackTrace (); return false;}} / / read the QQ account and password public static Map getUserInfo (Context context) {String content = ""; try {FileInputStream fis = context.openFileInput ("data.txt") from the data.txt file Byte [] buffer = new byte [fis.available ()]; / / set the size of the buffer fis.read (buffer); / / read buffer Map userMap = new HashMap (); content=new String (buffer); String [] infos = content.split (":"); / / to: cut the string userMap.put ("number", infos [0]) UserMap.put ("password", infos [1]); fis.close (); return userMap;} catch (Exception e) {return null After reading this, the article "how to develop and save QQ passwords in Android" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report