Analysis on Android mobile phone guard saving mobile phone security number

  • 2021-07-06 11:43:18
  • OfStack

Recommended reading:

Analysis of Android Mobile Phone Guardian sim Card Binding

In-depth analysis of md5 encryption when Android mobile phone guard saves password

Explanation of Android Mobile Guardian Setup Wizard Page

Analysis of Android Mobile Phone Guardian Turning off Automatic Update

Analysis on the Attributes of Android Mobile Guardian Custom Control

Analysis on Android Mobile Phone Guardian Reading Contacts

Call the setOnItemClickListener () method of the ListView object and set the click event of the entry. Parameter: OnItemClickListener object

Using an anonymous inner class implementation, overrides the onClick () method, passing in parameters: ListView, current View, position, id

Send back the current phone number according to the index position

Call the get () method of the List object to get Map, and call the get (key) method to get this phone

Call setResult () method, return data, parameter: response code, Intent object

Get the Intent object, and new comes out

Call putExtra (key, val) of the Intent object and put the phone in

Close the current page by calling the finish () method

The activity that opens this uses startActivityForResult ()

Override the onActivityResult () method and pass in the Intent object

Whether the Intent object is an null is judged

Call the getStringExtra () method of the Intent object to get the phone number

Put the phone on Edittext and save it to SP when you click next step

activity


package com.qingguow.mobilesafe;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
public class SecGuide3Activity extends BaseSecGuideActivity {
private EditText et_sec_phone;
private SharedPreferences sp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_lost_find3);
et_sec_phone = (EditText) findViewById(R.id.et_sec_phone);
sp = getSharedPreferences("config", MODE_PRIVATE);
String phone = sp.getString("secphone", "");
et_sec_phone.setText(phone);
}
public void nextStep(View v) {
showNext();
}
public void preStep(View v) {
showPre();
}
@Override
public void showPre() {
Intent intent = new Intent(this, SecGuide2Activity.class);
startActivity(intent);
finish();
}
@Override
public void showNext() {
String phone = et_sec_phone.getText().toString().trim();
if (TextUtils.isEmpty(phone)) {
Toast.makeText(this, " Please fill in the security number ", 1).show();
return;
}
Editor editor = sp.edit();
editor.putString("secphone", phone);
editor.commit();
Intent intent = new Intent(this, SecGuide4Activity.class);
startActivity(intent);
finish();
}
/**
*  Select Contacts 
*/
public void selectContacts(View v) {
Intent intent = new Intent(this, SelectContactsActivity.class);
startActivityForResult(intent, 0);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (data != null) {
String phone = data.getStringExtra("phone").replace("-", "")
.replace(" ", "");
et_sec_phone.setText(phone);
}
}
} 

SelectContactsActivity


package com.qingguow.mobilesafe;
import java.util.List;
import java.util.Map;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import com.qingguow.mobilesafe.utils.PhoneContactsUtil;
/**
*  Select Contacts 
* @author taoshihan
*
*/
public class SelectContactsActivity extends Activity {
private ListView lv_select_contacts;
private List<Map<String,String>> contacts;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_select_contacts);
lv_select_contacts=(ListView) findViewById(R.id.lv_select_contacts);
contacts=PhoneContactsUtil.getContacts(this);
lv_select_contacts.setAdapter(new SimpleAdapter(this, contacts, R.layout.select_contacts_item, new String[]{"name","phone"}, new int[]{R.id.tv_contact_name,R.id.tv_contact_phone}));
lv_select_contacts.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
String phone=contacts.get(position).get("phone");
Intent data=new Intent();
data.putExtra("phone", phone);
setResult(0, data);
finish();
}
});
}
}


Related articles: