How to call Android contacts list?

前端 未结 13 2265
傲寒
傲寒 2020-11-22 02:50

I\'m making an Android app, and need to call the phone\'s contact list. I need to call the contacts list function, pick a contact, then return to my app with the contact\'s

13条回答
  •  萌比男神i
    2020-11-22 03:29

    hi i have a code to save the contact in your database by shared preference here is my code

    public class Main22Activity extends AppCompatActivity {
        EditText nameInput,phoneInput;
        TextView LargeText;
    
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main22);
            nameInput = (EditText) findViewById(R.id.nameInput);
            phoneInput = (EditText) findViewById(R.id.phoneInput);
    
            LargeText = (TextView) findViewById(R.id.textView2);
        }
    
        public void saveInfo (View view){
            SharedPreferences sharedPref = getSharedPreferences("nameInfo" , Context.MODE_PRIVATE);
            SharedPreferences.Editor editor= sharedPref.edit();
            editor.putString("name", nameInput.getText().toString());
            editor.putString("phone", phoneInput.getText().toString());
            editor.apply();
            Toast.makeText(this, "Saved", Toast.LENGTH_LONG).show();
        }
    
        public void displayData(View view){
            SharedPreferences sharedPref = getSharedPreferences("nameInfo" , Context.MODE_PRIVATE);
            String name = sharedPref.getString("name", "");
            String ph = sharedPref.getString ("phone","");
            LargeText.setText(name + " " + ph);
        }
    }
    

提交回复
热议问题