SoFunction
Updated on 2025-04-09

Android development function to save QQ password

This article shares the specific code of Android's QQ password saving function for your reference. The specific content is as follows

Technical points:

Save data using file storage

Implementation steps:

①Design and implementation of user interaction interface
②Design and implementation of tool class (FileSaveQQjava)
③Design and implementation of interface logic code

Please see the page layout:Android development implements simple QQ login page

Code:

package ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
public class MainActivity extends AppCompatActivity implements  {
    private Button etLogin;
    private EditText etPassword;
    private EditText etNumber;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        (savedInstanceState);
        setContentView(.activity_main);
        //Initialize the view        initView();
        //If the user has saved it, data reprint        Map<String, String> userInfo = (this);
        if (userInfo!=null) {
            (("number"));
            (("password"));
        }
    }
    private void initView() {
//Initialize the control        etNumber = (EditText) findViewById(.et_number);
        etPassword = (EditText) findViewById(.et_password);
        etLogin = (Button) findViewById(.btn_login);
        //Set button click event        (this);
    }
    @Override
    public void onClick(View view) {
        //Click the button to get the account password        String number = ().toString().trim();
        String password = ().toString().trim();
        if ((number)) {
            (this, "Please enter QQ account", Toast.LENGTH_LONG).show();
            return;
        }
        if ((password)) {
            (this, "Please enter QQ password", Toast.LENGTH_LONG).show();
            return;
        }
        (this, "Login successfully", Toast.LENGTH_LONG).show();
//Save user information        boolean isSaveSucess = (this, number, password);
        if (isSaveSucess) {
            (this, "Save successfully", Toast.LENGTH_LONG).show();
        } else {
            (this, "Save failed", Toast.LENGTH_LONG).show();
        }
    }
}

File code:

package ;
import ;
import ;
import ;
import ;
import ;
import ;
public class FileSaveQQ {
    //Save user information    public static boolean saveUserInfo(Context context, String number, String password) {
        try {
            //Get file output stream through up and down stream            FileOutputStream fos = ("", context.MODE_PRIVATE);
            //Write the data into the file            ((number + ":" + password).getBytes());
            ();
            return true;
        } catch (Exception e) {
            ();
            return false;
        }
    }
    //Read the QQ account and password from the file    public static Map<String, String> getUserInfo(Context context) {
        String content = "";
        try {
            FileInputStream fis = ("");
            byte[] buffer = new byte[()];//Set the buffer size            (buffer);//Read the buffer            Map<String, String> userMap = new HashMap<String, String>();
            content=new String(buffer);
            String[] infos = (":");//Cut with: Cut string            ("number", infos[0]);
            ("password", infos[1]);
            ();
            return userMap;
        } catch (Exception e) {
            return null;
        }
    }
}

Refer to the book "Basic Case Tutorial on Android Mobile Development"

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.