Android开发手机通讯录

系统管理员 2021-10-06 18:36 651阅读 0赞

Android Studio开发手机通讯录

  • 课程设计
    • 课程设计要求
    • 课程设计题目
          • 题目1 通讯录管理
          • 题目2 拨号和短信管理
  • 代码实现
    • 首先我们先来理清楚思路
    • 创建数据库
    • 设置适配器
    • 主页面
    • 添加联系人活动
    • 编辑联系人活动
    • 主活动
    • 配置AndroidManifest.xml文件
    • 程序效果

课程设计

经过一个学期的Android开发学习,本次学期末,为了检验大家的学习情况,此次期末的课程设计为使用Android Studio开发一款手机通讯录

课程设计要求

  1. 分析课程设计题目,具有一定的需求分析的能力;
  2. 根据题目要求,具有算法设计能力和数据库处理能力;
  3. 理解安卓开发的的语法规则、编程思想,具有程序代码编写能力;
  4. 程序运行、调试能力;
  5. 设计完成后提交课程设计报告。
  6. 以下题目1必做,题目2选做。

课程设计题目

题目1 通讯录管理

功能要求如下:

  1. 本题目的要求为设计一个通讯录管理系统,通讯录的内容包括姓名、手机号码1、手机号码2、家庭座机号码、办公座机号码、地址和备注信息;
  2. 添加通讯录功能:用一个活动录入新的通讯录;
  3. 显示通讯录,用一个ListView显示所有通讯录的姓名和手机号码;
  4. 长按通讯录删除该通讯录条目;
  5. 设计相应的数据库表进行存取;
  6. 用word组织结构图画出所设计管理系统的功能模块;
  7. 截取每个活动的界面,存放到设计报告中;

运行程序后,在屏幕上显示通讯录。用户可以长按删除或用按钮添加通讯录。

题目2 拨号和短信管理

功能要求如下:
根据上题所做的通讯录,制作对应的拨号和短信功能,可以实现通讯录中点击对应的条目后选择应对的号码进行拨号或发送短信。

代码实现

首先我们先来理清楚思路

  1. 根据课程设计的需求,我们需要创建一个主页面,用来显示联系人的相关信息,如电话号码,名字,头像等(其中头像可以不用加进去)。
  2. 可以添加联系人,其中联系人存储在SQLite数据库中,所以我们还需要创建一个数据库文件,当然我们使用的是Android自带的数据库,可以使用一个java类进行数据库的创建即可。
  3. 我们需要添加的联系人可以从主页面点击添加按钮,跳转到添加联系人活动中,添加联系人的相关信息(姓名,联系方式1,联系方式2,家庭座机号,办公座机号,地址,备注),这里姓名属于必填项,同时,联系方式1、联系方式2、家庭座机号、办公座机号中必须填写一项,其余信息可以不用填写。
  4. 填写完成所有的信息后,点击保存按钮,将所填写的信息保存到数据库中
  5. 将所保存的联系人信息显示在主页面中,所以我们还需要创建一个listView的适配器。
  6. 可以实现打电话、发短信功能,所以我们需要去获取手机的打电话和发短息的相关权限。
  7. 实现编辑联系人功能(这一点课程设计要求中没有提到,小编觉得不管在多垃圾的联系人管理软件都应该支持联系人信息的编辑)
  8. 长按可以删除联系人
  9. 查看联系人相关信息

创建数据库

因为要求,我们需要把联系人存储到数据中,所以我们需要创建一个用来创建数据库的类,数据库中包含了我们所存储的联系人的所有信息,所以需要的字段有姓名、电话1、电话2、家庭电话、办公电话、地址、备注。具体代码实现如下:

  1. package com.example.myaddressbook;
  2. import android.content.Context;
  3. import android.database.sqlite.SQLiteDatabase;
  4. import android.database.sqlite.SQLiteOpenHelper;
  5. public class Datebase extends SQLiteOpenHelper {
  6. //定义创建数据库说用到的语句,并定制了数据库字段
  7. private static final String CREATE_PhoneNumber = "create table PhoneNumber(id integer primary key autoincrement, name text, " +
  8. "phone1 text, phone2 text, housePhone text, officePhone text,address text,remark text)";
  9. private Context mContext;
  10. public Datebase(Context context, String name, SQLiteDatabase.CursorFactory factory, int version){
  11. super(context, name, factory, version);
  12. mContext = context;
  13. }
  14. @Override
  15. public void onCreate(SQLiteDatabase sqLiteDatabase) {
  16. //创建数据库
  17. sqLiteDatabase.execSQL(CREATE_PhoneNumber);
  18. }
  19. @Override
  20. public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
  21. //升级数据库
  22. sqLiteDatabase.execSQL("drop table if exists PhoneNumber");
  23. onCreate(sqLiteDatabase);
  24. }
  25. }

到目前为止,我们创建好了我们程序所需要的数据库,需要使用数据库只需要在MainActivity中创建数据库类的对象即可。

设置适配器

定义所需要的联系人信息的类,制作ListView适配器,将我们所需要的信息添加到ListVie中。
首先,我们要创建一个Phone类,用来定义联系人所需要用到的信息,其实现代码如下:

  1. package com.example.myaddressbook;
  2. public class Phone {
  3. private String name,
  4. phone1,
  5. phone2,
  6. houerPhone,
  7. officephone,
  8. address,
  9. remark;
  10. public Phone(){
  11. }
  12. public String getName() {
  13. return name;
  14. }
  15. public String getPhone1() {
  16. return phone1;
  17. }
  18. public String getPhone2() {
  19. return phone2;
  20. }
  21. public String getHouerPhone() {
  22. return houerPhone;
  23. }
  24. public String getOfficephone() {
  25. return officephone;
  26. }
  27. public String getAddress() {
  28. return address;
  29. }
  30. public String getRemark() {
  31. return remark;
  32. }
  33. public Phone(String name, String phone1,String phone2,String houerPhone, String officephone,String address,String remark){
  34. this.name = name;
  35. this.phone1 = phone1;
  36. this.phone2 = phone2;
  37. this.houerPhone = houerPhone;
  38. this.officephone = officephone;
  39. this.address = address;
  40. this.remark = remark;
  41. }
  42. }

定义ListView适配器,定制LIstView,此时,我们需要创建一个布局文件,定制自己喜欢的布局,这里我设置的布局文件为一个嵌套布局,左边显示图片(头像)中间为内部嵌套布局文件,分为上下两个TextView,上面用来显示联系人的名字,下面用来显示联系人联系方式。右边有三个按钮,分别实现打电话功能、发短信功能、编辑联系人信息功能,布局样式如下:
定制ListView
定义好我们的定制listView之后,我们需要创建一个ListView适配器,其全部代码如下:

  1. package com.example.myaddressbook;
  2. import android.content.Context;
  3. import android.view.LayoutInflater;
  4. import android.view.View;
  5. import android.view.ViewGroup;
  6. import android.widget.ArrayAdapter;
  7. import android.widget.Button;
  8. import android.widget.ImageView;
  9. import android.widget.TextView;
  10. import androidx.annotation.NonNull;
  11. import androidx.annotation.Nullable;
  12. import java.util.List;
  13. public class ListAdapter extends ArrayAdapter<Phone>{
  14. private int resourceId;
  15. Phone phone = new Phone();
  16. public ListAdapter(Context context, int textViewResourceId, List<Phone> objects /*,MyCallback callback*/){
  17. super(context, textViewResourceId, objects);
  18. resourceId = textViewResourceId;
  19. // this.mCallback = callback;
  20. }
  21. @NonNull
  22. @Override
  23. public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
  24. final int i = position;
  25. Phone phone = (Phone)getItem(position);
  26. View view;
  27. ViewHolder viewHolder;
  28. if (convertView == null){
  29. view = LayoutInflater.from(getContext()).inflate(resourceId,parent,false);
  30. viewHolder = new ViewHolder();
  31. viewHolder.phoneImage = (ImageView)view.findViewById(R.id.phone_image);
  32. viewHolder.textViewName = (TextView)view.findViewById(R.id.list_name);
  33. viewHolder.textViewPhone = (TextView)view.findViewById(R.id.list_phone);
  34. viewHolder.buttonCall = (Button)view.findViewById(R.id.button_call);
  35. viewHolder.buttonChanges = (Button)view.findViewById(R.id.button_change);
  36. viewHolder.buttonShotMassage = (Button)view.findViewById(R.id.button_massages);
  37. view.setTag(viewHolder);
  38. }else{
  39. view = convertView;
  40. viewHolder = (ViewHolder) view.getTag();
  41. }
  42. viewHolder.phoneImage.setImageResource(R.drawable.ic_launcher_foreground);
  43. viewHolder.textViewName.setText(phone.getName());
  44. if (phone.getPhone1().equals("")){
  45. if (phone.getPhone2().equals("")){
  46. if (phone.getHouerPhone().equals("")){
  47. viewHolder.textViewPhone.setText(phone.getOfficephone());
  48. }else{
  49. viewHolder.textViewPhone.setText(phone.getHouerPhone());
  50. }
  51. }else {
  52. viewHolder.textViewPhone.setText(phone.getPhone2());
  53. }
  54. }else {
  55. viewHolder.textViewPhone.setText(phone.getPhone1());
  56. }
  57. viewHolder.buttonCall.setOnClickListener(new View.OnClickListener(){
  58. @Override
  59. public void onClick(View v){
  60. mOnItemCallListener.onCallClick(i);
  61. }
  62. });
  63. viewHolder.buttonChanges.setOnClickListener(new View.OnClickListener() {
  64. @Override
  65. public void onClick(View view) {
  66. mOnItemChangesListener.onChangesClick(i);
  67. }
  68. });
  69. viewHolder.buttonShotMassage.setOnClickListener(new View.OnClickListener() {
  70. @Override
  71. public void onClick(View view) {
  72. mOnItemMassgasListener.onMassgasClick(i);
  73. }
  74. });
  75. return view;
  76. }
  77. class ViewHolder{
  78. ImageView phoneImage;
  79. TextView textViewName;
  80. TextView textViewPhone;
  81. Button buttonCall;
  82. Button buttonChanges;
  83. Button buttonShotMassage;
  84. }
  85. public interface onItemCallListener {
  86. void onCallClick(int i);
  87. }
  88. private onItemCallListener mOnItemCallListener;
  89. public void setOnItemCallClickListener(onItemCallListener mOnItemCallListener) {
  90. this.mOnItemCallListener = mOnItemCallListener;
  91. }
  92. public interface onItemChangesListener {
  93. void onChangesClick(int i);
  94. }
  95. private onItemChangesListener mOnItemChangesListener;
  96. public void setOnItemChangesClickListener(onItemChangesListener mOnItemChangersListener) {
  97. this.mOnItemChangesListener = mOnItemChangersListener;
  98. }
  99. public interface onItemMassgasListener {
  100. void onMassgasClick(int i);
  101. }
  102. private onItemMassgasListener mOnItemMassgasListener;
  103. public void setOnItemMassgasClickListener(onItemMassgasListener mOnItemMassgasListener) {
  104. this.mOnItemMassgasListener = mOnItemMassgasListener;
  105. }
  106. }

主页面

创建一个项目,这里小编创建的项目为MyAddressBook。项目创建好之后在activity_main.xml文件中设置布局,因为需要联系人按列表显示,所以在布局文件中使用一个ListView控件,同时添加一个Button,用来添加联系人使用。具体布局详情以及布局文件如下所示:
主页面布局

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. xmlns:tools="http://schemas.android.com/tools"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent"
  7. tools:context=".MainActivity">
  8. <ListView
  9. android:layout_width="match_parent"
  10. android:layout_height="match_parent"
  11. android:scrollbars="vertical"
  12. android:fadeScrollbars="true"
  13. android:id="@+id/list_list"
  14. />
  15. <Button
  16. android:layout_width="50dp"
  17. android:layout_height="50dp"
  18. android:id="@+id/button_add"
  19. android:padding="0dp"
  20. android:layout_alignParentBottom="true"
  21. android:layout_alignParentRight="true"
  22. android:textSize="25dp"
  23. android:textColor="#FC752D"
  24. android:background="@mipmap/add_phone"
  25. android:layout_margin="30dp"
  26. />
  27. </RelativeLayout>

在上述代码中,使用的是相对布局,同时包含了ListView和Button,ListView用来显示联系人信息,Button用来点击跳转至添加联系人活动中。(这里小编技术不够,使用相对布局和ListView的特性设置了一个伪浮动按钮,大神勿喷!)

添加联系人活动

根据课程设计要求,我们在点击主页面的添加按钮之后会跳转到添加联系人活动中,所以我们需要创建一个添加联系人的活动。
首先我们需要设置好我们的布局文件,代码和效果如下:
添加联系人布局
添加联系人的页面布局代码具体实现如下:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. xmlns:tools="http://schemas.android.com/tools"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent"
  7. android:id="@+id/wrap"
  8. tools:context=".AddPhoneNumber">
  9. <RelativeLayout
  10. android:layout_width="match_parent"
  11. android:layout_height="wrap_content"
  12. android:id="@+id/line1"
  13. android:layout_marginTop="10dp"
  14. >
  15. <Button
  16. android:layout_width="wrap_content"
  17. android:layout_height="wrap_content"
  18. android:id="@+id/back"
  19. android:textColor="#2BFFDB"
  20. android:textSize="17dp"
  21. android:layout_alignParentLeft="true"
  22. android:layout_marginLeft="10dp"
  23. android:text="@string/back"
  24. android:background="@drawable/button_background"/>
  25. <Button
  26. android:id="@+id/save"
  27. android:layout_width="wrap_content"
  28. android:layout_height="wrap_content"
  29. android:background="@drawable/button_background"
  30. android:layout_marginRight="10dp"
  31. android:layout_alignParentRight="true"
  32. android:textColor="#17E910"
  33. android:textSize="17dp"
  34. android:text="保存" />
  35. </RelativeLayout>
  36. <TextView
  37. android:layout_width="wrap_content"
  38. android:layout_below="@id/line1"
  39. android:layout_height="wrap_content"
  40. android:id="@+id/button_name"
  41. android:textSize="15dp"
  42. android:textColor="#4BDBEE"
  43. android:layout_marginTop="37dp"
  44. android:layout_marginLeft="50dp"
  45. android:text="姓 名:"/>
  46. <TextView
  47. android:layout_width="wrap_content"
  48. android:layout_height="wrap_content"
  49. android:id="@+id/button_phone_number1"
  50. android:textSize="15dp"
  51. android:textColor="#4BDBEE"
  52. android:layout_marginTop="25dp"
  53. android:layout_marginLeft="50dp"
  54. android:layout_below="@id/button_name"
  55. android:text="手 机 号 码 1 :"/>
  56. <TextView
  57. android:layout_width="wrap_content"
  58. android:layout_height="wrap_content"
  59. android:textSize="15dp"
  60. android:textColor="#4BDBEE"
  61. android:layout_marginTop="25dp"
  62. android:layout_marginLeft="50dp"
  63. android:id="@+id/button_phone_number2"
  64. android:layout_below="@id/button_phone_number1"
  65. android:text="手 机 号 码 2 :"/>
  66. <TextView
  67. android:layout_width="wrap_content"
  68. android:layout_height="wrap_content"
  69. android:textSize="15dp"
  70. android:textColor="#4BDBEE"
  71. android:layout_marginTop="25dp"
  72. android:layout_marginLeft="50dp"
  73. android:layout_below="@id/button_phone_number2"
  74. android:id="@+id/button_house_number"
  75. android:text="家 庭 座 机 号:"/>
  76. <TextView
  77. android:layout_width="wrap_content"
  78. android:layout_height="wrap_content"
  79. android:id="@+id/button_office_number"
  80. android:textSize="15dp"
  81. android:textColor="#4BDBEE"
  82. android:layout_marginTop="25dp"
  83. android:layout_marginLeft="50dp"
  84. android:layout_below="@id/button_house_number"
  85. android:text="办公座机号码:"/>
  86. <TextView
  87. android:layout_width="wrap_content"
  88. android:layout_height="wrap_content"
  89. android:id="@+id/button_address"
  90. android:textSize="15dp"
  91. android:textColor="#4BDBEE"
  92. android:layout_marginTop="25dp"
  93. android:layout_marginLeft="50dp"
  94. android:layout_below="@id/button_office_number"
  95. android:text="地 址:"/>
  96. <TextView
  97. android:layout_width="wrap_content"
  98. android:layout_height="wrap_content"
  99. android:id="@+id/button_remark"
  100. android:textSize="15dp"
  101. android:textColor="#4BDBEE"
  102. android:layout_marginTop="25dp"
  103. android:layout_marginLeft="50dp"
  104. android:layout_below="@id/button_address"
  105. android:text="备 注:"/>
  106. <EditText
  107. android:layout_width="200dp"
  108. android:layout_height="wrap_content"
  109. android:layout_below="@id/line1"
  110. android:inputType="text"
  111. android:textColor="#F40"
  112. android:textSize="15dp"
  113. android:maxLength="10"
  114. android:hint="请输入姓名"
  115. android:layout_marginTop="27dp"
  116. android:layout_toRightOf="@id/button_name"
  117. android:id="@+id/edit_name"/>
  118. <EditText
  119. android:layout_width="200dp"
  120. android:layout_height="wrap_content"
  121. android:inputType="number"
  122. android:textColor="#F40"
  123. android:textSize="15dp"
  124. android:layout_marginTop="3dp"
  125. android:hint="请输入电话号码"
  126. android:maxLength="11"
  127. android:layout_below="@id/edit_name"
  128. android:layout_toRightOf="@id/button_phone_number1"
  129. android:id="@+id/edit_phone_number1"/>
  130. <EditText
  131. android:layout_width="200dp"
  132. android:inputType="number"
  133. android:layout_below="@id/edit_phone_number1"
  134. android:layout_height="wrap_content"
  135. android:maxLength="11"
  136. android:layout_marginTop="4dp"
  137. android:textColor="#F40"
  138. android:textSize="15dp"
  139. android:hint="请输入电话号码"
  140. android:layout_toRightOf="@id/button_phone_number2"
  141. android:id="@+id/edit_phone_number2"/>
  142. <EditText
  143. android:layout_width="200dp"
  144. android:layout_height="wrap_content"
  145. android:textColor="#F40"
  146. android:textSize="15dp"
  147. android:inputType="number"
  148. android:layout_marginTop="4dp"
  149. android:hint="请输入家庭座机"
  150. android:maxLength="12"
  151. android:layout_toRightOf="@id/button_house_number"
  152. android:layout_below="@id/edit_phone_number2"
  153. android:id="@+id/edit_house_number"/>
  154. <EditText
  155. android:layout_width="200dp"
  156. android:layout_below="@id/edit_house_number"
  157. android:layout_toRightOf="@id/button_office_number"
  158. android:layout_marginTop="4dp"
  159. android:inputType="number"
  160. android:layout_height="wrap_content"
  161. android:textColor="#F40"
  162. android:textSize="15dp"
  163. android:hint="请输入办公座机"
  164. android:maxLength="12"
  165. android:id="@+id/edit_office_number"/>
  166. <EditText
  167. android:layout_width="200dp"
  168. android:layout_height="wrap_content"
  169. android:inputType="text"
  170. android:layout_marginTop="4dp"
  171. android:textColor="#F40"
  172. android:textSize="15dp"
  173. android:hint="请输入地址"
  174. android:maxLength="20"
  175. android:layout_toRightOf="@id/button_address"
  176. android:layout_below="@id/edit_office_number"
  177. android:id="@+id/edit_address"/>
  178. <EditText
  179. android:layout_width="200dp"
  180. android:textColor="#F40"
  181. android:textSize="15dp"
  182. android:hint="请输入备注信息"
  183. android:layout_marginTop="4dp"
  184. android:layout_below="@id/edit_address"
  185. android:layout_toRightOf="@id/button_remark"
  186. android:layout_height="wrap_content"
  187. android:inputType="text"
  188. android:maxLength="30"
  189. android:id="@+id/edit_remark"/>
  190. </RelativeLayout>

这里小编使用的也是相对布局,同时还使用了布局嵌套,在相对布局中嵌套一个布局,将title和下面的添加用户的信息分离,在内部嵌套的布局中,添加了两个按钮,这两个按钮的作用分别是返回主页面和保存所填写的用户信息,将信息提交到数据库。

其Activity代码实现文件如下:

  1. package com.example.myaddressbook;
  2. import androidx.appcompat.app.AppCompatActivity;
  3. import android.content.ContentValues;
  4. import android.content.Intent;
  5. import android.database.Cursor;
  6. import android.database.sqlite.SQLiteDatabase;
  7. import android.os.Bundle;
  8. import android.view.View;
  9. import android.widget.Button;
  10. import android.widget.EditText;
  11. import android.widget.Toast;
  12. public class AddPhoneNumber extends AppCompatActivity {
  13. //定义所需要使用到的button和EditText控件对象
  14. Button buttonBack;
  15. Button buttonSave;
  16. EditText editTextName,
  17. editTextPhone1,
  18. editTextPhone2,
  19. editTextHousePhone,
  20. editTextOfficePhone,
  21. editTextAddress,
  22. editTextRemark;
  23. //电仪数据库类型的变量
  24. private Datebase datebase;
  25. SQLiteDatabase db;
  26. @Override
  27. protected void onCreate(Bundle savedInstanceState) {
  28. super.onCreate(savedInstanceState);
  29. setContentView(R.layout.activity_add_phone_number);
  30. //创建数据库对象
  31. datebase = new Datebase(this,"PhoneNumber",null,1);
  32. //创建控件对象
  33. buttonBack = (Button) findViewById(R.id.back);
  34. buttonSave = (Button) findViewById(R.id.save);
  35. editTextName = (EditText) findViewById(R.id.edit_name);
  36. editTextPhone1 = (EditText)findViewById(R.id.edit_phone_number1);
  37. editTextPhone2 = (EditText)findViewById(R.id.edit_phone_number2);
  38. editTextHousePhone = (EditText)findViewById(R.id.edit_house_number);
  39. editTextOfficePhone = (EditText)findViewById(R.id.edit_office_number);
  40. editTextAddress = (EditText)findViewById(R.id.edit_address);
  41. editTextRemark = (EditText)findViewById(R.id.edit_remark);
  42. //设置点击返回按钮时触发的事件
  43. buttonBack.setOnClickListener(new View.OnClickListener() {
  44. @Override
  45. public void onClick(View view) {
  46. //设置事件为返回到主活动中
  47. Intent intent = new Intent(AddPhoneNumber.this,MainActivity.class);
  48. startActivity(intent);
  49. }
  50. });
  51. //定义保存按钮被触发是的事件
  52. buttonSave.setOnClickListener(new View.OnClickListener() {
  53. @Override
  54. public void onClick(View view) {
  55. // 定义字符串,并写获取EditText输入框中的文字
  56. String edit_name = editTextName.getText().toString(),
  57. edit_phone1 = editTextPhone1.getText().toString(),
  58. edit_phone2 = editTextPhone2.getText().toString(),
  59. edit_housePhone = editTextHousePhone.getText().toString(),
  60. edit_officePhone = editTextOfficePhone.getText().toString(),
  61. edit_address = editTextAddress.getText().toString(),
  62. edit_remark = editTextRemark.getText().toString();
  63. // 判断输入的联系人姓名是否为空和联系方式1、联系方式2、家庭座机、办公座机其中一个是否不为空
  64. if ((!edit_name.equals("")) && (!edit_phone1.equals("") || !edit_phone2.equals("") || !edit_housePhone.equals("") || !edit_officePhone.equals(""))){
  65. //定义一个计数器,用来判断数据库中是否存在此联系人
  66. int count = 0;
  67. //定义可操作的数据库对象
  68. db = datebase.getWritableDatabase();
  69. //设置Curso对象,用来查看数据库中的信息
  70. Cursor cursor = db.query("PhoneNumber",null,null,null,null,null,null);
  71. //判断数据库是否为空
  72. if (cursor.moveToFirst()){
  73. do{
  74. // 获取数据库中的信息,并且赋值给所定义的字符串,括号内为数据库字段名称
  75. String name = cursor.getString(cursor.getColumnIndex("name"));
  76. String phone1 = cursor.getString(cursor.getColumnIndex("phone1"));
  77. String phone2 = cursor.getString(cursor.getColumnIndex("phone2"));
  78. String housePhone = cursor.getString(cursor.getColumnIndex("housePhone"));
  79. String officePone = cursor.getString(cursor.getColumnIndex("officePhone"));
  80. String address = cursor.getString(cursor.getColumnIndex("address"));
  81. String remark = cursor.getString(cursor.getColumnIndex("remark"));
  82. //判断数据库中是否已经存在输入的联系人的姓名,或者是否存在输入的信息相同的信息
  83. if ((name.equals(edit_name) && phone1.equals(edit_phone1)) && (phone2.equals(edit_phone2) && housePhone.equals(edit_housePhone)) &&
  84. (officePone.equals(edit_officePhone) && address.equals(edit_address) && remark.equals(edit_remark)) || name.equals(edit_name)){
  85. // 如果存在相同的,那么count自增
  86. count ++;
  87. }
  88. }while (cursor.moveToNext());
  89. }
  90. // 如果输入的信息不相同,也就是count没有进行运算
  91. if (count == 0){
  92. // 定义可写的数据库
  93. SQLiteDatabase db = datebase.getWritableDatabase();
  94. // 创建ContentValues对象
  95. ContentValues values = new ContentValues();
  96. // 调用put方法添加数据到ContentValues对象中
  97. values.put("name",edit_name);
  98. values.put("phone1", edit_phone1);
  99. values.put("phone2", edit_phone2);
  100. values.put("housePhone", edit_housePhone);
  101. values.put("officePhone", edit_officePhone);
  102. values.put("address",edit_address);
  103. values.put("remark", edit_remark);
  104. // 添加数据到数据库表中
  105. db.insert("PhoneNumber",null,values);
  106. // 清楚values的数据
  107. values.clear();
  108. // 提示保存成功
  109. Toast.makeText(AddPhoneNumber.this,"保存成功!",Toast.LENGTH_SHORT).show();
  110. // 跳转回主界面
  111. Intent intent = new Intent(AddPhoneNumber.this,MainActivity.class);
  112. startActivity(intent);
  113. }else{
  114. // 如果联系人已经存在,提示已经存在
  115. Toast.makeText(AddPhoneNumber.this,"联系人已存在!",Toast.LENGTH_SHORT).show();
  116. }
  117. }else{
  118. // 如果输入的必要信息没有填写,则会提示
  119. Toast.makeText(AddPhoneNumber.this,"请填写联系人相关信息!",Toast.LENGTH_SHORT).show();
  120. }
  121. }
  122. });
  123. }
  124. }

编辑联系人活动

这里是小编加入的一个而外的功能,可以对已经存储好的联系人的信息进行修改,布局文件如下所示:
编辑联系人信息活动

布局文件的代码实现入下:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. xmlns:tools="http://schemas.android.com/tools"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent"
  7. tools:context=".EditPhone">
  8. <RelativeLayout
  9. android:layout_width="match_parent"
  10. android:layout_height="wrap_content"
  11. android:id="@+id/check_line1"
  12. android:layout_marginTop="10dp"
  13. >
  14. <Button
  15. android:layout_width="wrap_content"
  16. android:layout_height="wrap_content"
  17. android:id="@+id/check_back"
  18. android:textColor="#2BFFDB"
  19. android:textSize="17dp"
  20. android:layout_alignParentLeft="true"
  21. android:layout_marginLeft="10dp"
  22. android:text="@string/back"
  23. android:background="@drawable/button_background"/>
  24. <Button
  25. android:id="@+id/check_save"
  26. android:layout_width="wrap_content"
  27. android:layout_height="wrap_content"
  28. android:background="@drawable/button_background"
  29. android:layout_marginRight="10dp"
  30. android:layout_alignParentRight="true"
  31. android:textColor="#17E910"
  32. android:textSize="17dp"
  33. android:text="保存" />
  34. </RelativeLayout>
  35. <TextView
  36. android:layout_width="wrap_content"
  37. android:layout_below="@id/check_line1"
  38. android:layout_height="wrap_content"
  39. android:id="@+id/check_button_name"
  40. android:textSize="15dp"
  41. android:textColor="#4BDBEE"
  42. android:layout_marginTop="37dp"
  43. android:layout_marginLeft="50dp"
  44. android:text="姓 名:"/>
  45. <TextView
  46. android:layout_width="wrap_content"
  47. android:layout_height="wrap_content"
  48. android:id="@+id/check_button_phone_number1"
  49. android:textSize="15dp"
  50. android:textColor="#4BDBEE"
  51. android:layout_marginTop="25dp"
  52. android:layout_marginLeft="50dp"
  53. android:layout_below="@id/check_button_name"
  54. android:text="手 机 号 码 1 :"/>
  55. <TextView
  56. android:layout_width="wrap_content"
  57. android:layout_height="wrap_content"
  58. android:textSize="15dp"
  59. android:textColor="#4BDBEE"
  60. android:layout_marginTop="25dp"
  61. android:layout_marginLeft="50dp"
  62. android:id="@+id/check_button_phone_number2"
  63. android:layout_below="@id/check_button_phone_number1"
  64. android:text="手 机 号 码 2 :"/>
  65. <TextView
  66. android:layout_width="wrap_content"
  67. android:layout_height="wrap_content"
  68. android:textSize="15dp"
  69. android:textColor="#4BDBEE"
  70. android:layout_marginTop="25dp"
  71. android:layout_marginLeft="50dp"
  72. android:layout_below="@id/check_button_phone_number2"
  73. android:id="@+id/check_button_house_number"
  74. android:text="家 庭 座 机 号:"/>
  75. <TextView
  76. android:layout_width="wrap_content"
  77. android:layout_height="wrap_content"
  78. android:id="@+id/check_button_office_number"
  79. android:textSize="15dp"
  80. android:textColor="#4BDBEE"
  81. android:layout_marginTop="25dp"
  82. android:layout_marginLeft="50dp"
  83. android:layout_below="@id/check_button_house_number"
  84. android:text="办公座机号码:"/>
  85. <TextView
  86. android:layout_width="wrap_content"
  87. android:layout_height="wrap_content"
  88. android:id="@+id/check_button_address"
  89. android:textSize="15dp"
  90. android:textColor="#4BDBEE"
  91. android:layout_marginTop="25dp"
  92. android:layout_marginLeft="50dp"
  93. android:layout_below="@id/check_button_office_number"
  94. android:text="地 址:"/>
  95. <TextView
  96. android:layout_width="wrap_content"
  97. android:layout_height="wrap_content"
  98. android:id="@+id/check_button_remark"
  99. android:textSize="15dp"
  100. android:textColor="#4BDBEE"
  101. android:layout_marginTop="25dp"
  102. android:layout_marginLeft="50dp"
  103. android:layout_below="@id/check_button_address"
  104. android:text="备 注:"/>
  105. <EditText
  106. android:layout_width="200dp"
  107. android:layout_height="wrap_content"
  108. android:layout_below="@id/check_line1"
  109. android:inputType="text"
  110. android:textColor="#F40"
  111. android:textSize="15dp"
  112. android:hint="无"
  113. android:layout_marginTop="27dp"
  114. android:layout_toRightOf="@id/check_button_name"
  115. android:id="@+id/check_edit_name"/>
  116. <EditText
  117. android:layout_width="200dp"
  118. android:layout_height="wrap_content"
  119. android:inputType="number"
  120. android:textColor="#F40"
  121. android:textSize="15dp"
  122. android:layout_marginTop="3dp"
  123. android:hint="无"
  124. android:maxLength="11"
  125. android:layout_below="@id/check_edit_name"
  126. android:layout_toRightOf="@id/check_button_phone_number1"
  127. android:id="@+id/check_edit_phone_number1"/>
  128. <EditText
  129. android:layout_width="200dp"
  130. android:layout_below="@id/check_edit_phone_number1"
  131. android:layout_height="wrap_content"
  132. android:inputType="number"
  133. android:maxLength="11"
  134. android:layout_marginTop="4dp"
  135. android:textColor="#F40"
  136. android:textSize="15dp"
  137. android:hint="无"
  138. android:layout_toRightOf="@id/check_button_phone_number2"
  139. android:id="@+id/check_edit_phone_number2"/>
  140. <EditText
  141. android:layout_width="200dp"
  142. android:layout_height="wrap_content"
  143. android:textColor="#F40"
  144. android:textSize="15dp"
  145. android:layout_marginTop="4dp"
  146. android:inputType="number"
  147. android:hint="无"
  148. android:maxLength="12"
  149. android:layout_toRightOf="@id/check_button_house_number"
  150. android:layout_below="@id/check_edit_phone_number2"
  151. android:id="@+id/check_edit_house_number"/>
  152. <EditText
  153. android:layout_width="200dp"
  154. android:layout_below="@id/check_edit_house_number"
  155. android:layout_toRightOf="@id/check_button_office_number"
  156. android:layout_marginTop="4dp"
  157. android:layout_height="wrap_content"
  158. android:inputType="number"
  159. android:textColor="#F40"
  160. android:textSize="15dp"
  161. android:hint="无"
  162. android:maxLength="12"
  163. android:id="@+id/check_edit_office_number"/>
  164. <EditText
  165. android:layout_width="200dp"
  166. android:layout_height="wrap_content"
  167. android:inputType="text"
  168. android:layout_marginTop="4dp"
  169. android:textColor="#F40"
  170. android:textSize="15dp"
  171. android:hint="无"
  172. android:layout_toRightOf="@id/check_button_address"
  173. android:layout_below="@id/check_edit_office_number"
  174. android:id="@+id/check_edit_address"/>
  175. <EditText
  176. android:layout_width="200dp"
  177. android:textColor="#F40"
  178. android:textSize="15dp"
  179. android:hint="无"
  180. android:layout_marginTop="4dp"
  181. android:layout_below="@id/check_edit_address"
  182. android:layout_toRightOf="@id/check_button_remark"
  183. android:layout_height="wrap_content"
  184. android:inputType="text"
  185. android:id="@+id/check_edit_remark"/>
  186. </RelativeLayout>

其所对应 Activity代码如下:

  1. package com.example.myaddressbook;
  2. import androidx.appcompat.app.AppCompatActivity;
  3. import android.content.ContentValues;
  4. import android.content.Intent;
  5. import android.database.Cursor;
  6. import android.database.sqlite.SQLiteDatabase;
  7. import android.os.Bundle;
  8. import android.view.View;
  9. import android.widget.Button;
  10. import android.widget.EditText;
  11. import android.widget.ListView;
  12. import android.widget.Toast;
  13. import java.util.ArrayList;
  14. import java.util.List;
  15. public class EditPhone extends AppCompatActivity {
  16. Button buttonCheck,
  17. buttonSave;
  18. EditText editTextName,
  19. editTextPhone1,
  20. editTextPhone2,
  21. editTextHousePhone,
  22. editTextOfficePhone,
  23. editTextAddress,
  24. editTextRemark;
  25. private Datebase datebase;
  26. SQLiteDatabase db;
  27. int i;
  28. Datebase dbHelper = new Datebase(this,"PhoneNumber",null,1);
  29. @Override
  30. protected void onCreate(Bundle savedInstanceState) {
  31. super.onCreate(savedInstanceState);
  32. setContentView(R.layout.activity_check);
  33. buttonSave = findViewById(R.id.check_save);
  34. buttonCheck = findViewById(R.id.check_back);
  35. editTextName = findViewById(R.id.check_edit_name);
  36. editTextPhone1 = findViewById(R.id.check_edit_phone_number1);
  37. editTextPhone2 = findViewById(R.id.check_edit_phone_number2);
  38. editTextHousePhone = findViewById(R.id.check_edit_house_number);
  39. editTextOfficePhone = findViewById(R.id.check_edit_office_number);
  40. editTextAddress = findViewById(R.id.check_edit_address);
  41. editTextRemark = findViewById(R.id.check_edit_remark);
  42. datebase = new Datebase(this,"PhoneNumber",null,1);
  43. buttonCheck.setOnClickListener(new View.OnClickListener() {
  44. @Override
  45. public void onClick(View view) {
  46. Intent intent = new Intent(EditPhone.this,MainActivity.class);
  47. startActivity(intent);
  48. }
  49. });
  50. //获取从中活动传递下来的数据
  51. Intent intent = getIntent();
  52. editTextName.setText(intent.getStringExtra("extra_name"));
  53. editTextPhone1.setText(intent.getStringExtra("extra_phone1"));
  54. editTextPhone2.setText(intent.getStringExtra("extra_phone2"));
  55. editTextHousePhone.setText(intent.getStringExtra("extra_housePhone"));
  56. editTextOfficePhone.setText(intent.getStringExtra("extra_officePhone"));
  57. editTextAddress.setText(intent.getStringExtra("extra_address"));
  58. editTextRemark.setText(intent.getStringExtra("extra_remark"));
  59. i = intent.getIntExtra("extra_i",0);
  60. final String editName = intent.getStringExtra("extra_name");
  61. buttonSave.setOnClickListener(new View.OnClickListener() {
  62. @Override
  63. public void onClick(View view) {
  64. ContentValues values = new ContentValues();
  65. //获取用户此时输入的数据
  66. String edName = editTextName.getText().toString(),
  67. edPhone1 = editTextPhone1.getText().toString(),
  68. edPhone2 = editTextPhone2.getText().toString(),
  69. edHousePhone = editTextHousePhone.getText().toString(),
  70. edOfficePhone = editTextOfficePhone.getText().toString(),
  71. edAddress = editTextAddress.getText().toString(),
  72. edRemark = editTextRemark.getText().toString();
  73. db = datebase.getWritableDatabase();
  74. int ID = 0;
  75. Cursor cursor = db.query("PhoneNumber",null,null,null,null,null,null);
  76. if (cursor.moveToFirst()){
  77. do{
  78. // 获取此联系人在数据库表中的名字
  79. String name = cursor.getString(cursor.getColumnIndex("name"));
  80. // 对比名字是否符合
  81. if (name.equals(editName)){
  82. // 名字符合则获取此联系人在数据库表中的主键id
  83. ID = cursor.getInt((cursor.getColumnIndex("id")));
  84. break;
  85. }
  86. }while (cursor.moveToNext());
  87. }
  88. values.put("name",edName);
  89. values.put("phone1", edPhone1);
  90. values.put("phone2", edPhone2);
  91. values.put("housePhone", edHousePhone);
  92. values.put("officePhone", edOfficePhone);
  93. values.put("address",edAddress);
  94. values.put("remark", edRemark);
  95. // 将所输入的信息提交至数据库修改,使用条件为主键等于刚刚所获取的主键值
  96. db.update("PhoneNumber",values,"id = ?",new String[]{ String.valueOf(ID)});
  97. values.clear();
  98. Toast.makeText(EditPhone.this,"保存成功!",Toast.LENGTH_SHORT).show();
  99. Intent intent1 = new Intent(EditPhone.this,MainActivity.class);
  100. startActivity(intent1);
  101. }
  102. });
  103. setReadOnly(editTextRemark);
  104. }
  105. }

主活动

但我们设置好我们所有的布局文件和相关的Activity文件之后,我们就可以在主活动中进行我们整个程序额逻辑实现,当然并不是最后才写我们的主活动,而是需要配合着活动,慢慢调试我们的程序的功能。
MainActivity的全部代码如下:

  1. package com.example.myaddressbook;
  2. import androidx.appcompat.app.AlertDialog;
  3. import androidx.appcompat.app.AppCompatActivity;
  4. import android.content.DialogInterface;
  5. import android.content.Intent;
  6. import android.database.Cursor;
  7. import android.database.sqlite.SQLiteDatabase;
  8. import android.net.Uri;
  9. import android.os.Bundle;
  10. import android.view.View;
  11. import android.widget.AdapterView;
  12. import android.widget.Button;
  13. import android.widget.ListView;
  14. import android.widget.Toast;
  15. import java.util.ArrayList;
  16. import java.util.List;
  17. public class MainActivity extends AppCompatActivity {
  18. Button buttonAdd ;
  19. ListView listViewPhone;
  20. private List<Phone> phones= new ArrayList<>();
  21. ListAdapter adapter;
  22. SQLiteDatabase db;
  23. Datebase dbHelper = new Datebase(this,"PhoneNumber",null,1);
  24. @Override
  25. protected void onCreate(Bundle savedInstanceState) {
  26. super.onCreate(savedInstanceState);
  27. setContentView(R.layout.activity_main);
  28. buttonAdd = findViewById(R.id.button_add);
  29. listViewPhone = findViewById(R.id.list_list);
  30. buttonAdd.setOnClickListener(new View.OnClickListener() {
  31. @Override
  32. public void onClick(View view) {
  33. Intent intent = new Intent(MainActivity.this,AddPhoneNumber.class);
  34. startActivity(intent);
  35. }
  36. });
  37. db = dbHelper.getWritableDatabase();
  38. Cursor cursor = db.query("PhoneNumber",null,null,null,null,null,null);
  39. if (cursor.moveToFirst()){
  40. do{
  41. String name = cursor.getString(cursor.getColumnIndex("name"));
  42. String phone1 = cursor.getString(cursor.getColumnIndex("phone1"));
  43. String phone2 = cursor.getString(cursor.getColumnIndex("phone2"));
  44. String housePhone = cursor.getString(cursor.getColumnIndex("housePhone"));
  45. String officePone = cursor.getString(cursor.getColumnIndex("officePhone"));
  46. String address = cursor.getString(cursor.getColumnIndex("address"));
  47. String remark = cursor.getString(cursor.getColumnIndex("remark"));
  48. Phone phoneInfo = new Phone(name,phone1,phone2,housePhone,officePone,address,remark);
  49. phones.add(phoneInfo);
  50. }while (cursor.moveToNext());
  51. }
  52. adapter = new ListAdapter(MainActivity.this,R.layout.list_item, phones);
  53. listViewPhone.setAdapter(adapter);
  54. listViewPhone.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  55. @Override
  56. public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
  57. Phone phone_check = phones.get(i);
  58. String checkName = phone_check.getName(),
  59. checkPhone1 = phone_check.getPhone1(),
  60. checkPhone2 = phone_check.getPhone2(),
  61. checkHousePhone = phone_check.getHouerPhone(),
  62. checkOfficePhone = phone_check.getOfficephone(),
  63. checkAddress = phone_check.getAddress(),
  64. checkRemark = phone_check.getRemark();
  65. AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
  66. builder.setMessage(
  67. " 姓 名:" + checkName + "\n" +
  68. " 联 系 方 式 1 :" + checkPhone1 + "\n" +
  69. " 联 系 方 式 2 :" + checkPhone2 + "\n" +
  70. " 家 庭 座 机 号:" + checkHousePhone + "\n" +
  71. " 办 公 座 机 号:" + checkOfficePhone + "\n" +
  72. " 地 址 :" + checkAddress + "\n" +
  73. " 备 注 :" + checkRemark + "\n");
  74. builder.setTitle(" 查看联系人");
  75. builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
  76. @Override
  77. public void onClick(DialogInterface dialogInterface, int i) {
  78. }
  79. });
  80. builder.show();
  81. // Intent intent = new Intent(MainActivity.this,EditPhone.class);
  82. // intent.putExtra("extra_name",checkName);
  83. // intent.putExtra("extra_phone1",checkPhone1);
  84. // intent.putExtra("extra_phone2",checkPhone2);
  85. // intent.putExtra("extra_housePhone",checkHousePhone);
  86. // intent.putExtra("extra_officePhone",checkOfficePhone);
  87. // intent.putExtra("extra_address",checkAddress);
  88. // intent.putExtra("extra_remark",checkRemark);
  89. // startActivity(intent);
  90. }
  91. });
  92. listViewPhone.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
  93. @Override
  94. public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
  95. DeleteDialog(i);
  96. return true;
  97. }
  98. });
  99. adapter.setOnItemCallClickListener(new ListAdapter.onItemCallListener() {
  100. @Override
  101. public void onCallClick(int i) {
  102. Phone phone_check = phones.get(i);
  103. String phoneNumber = phone_check.getPhone1();
  104. Intent intent = new Intent();
  105. intent.setAction(Intent.ACTION_DIAL);
  106. intent.setData(Uri.parse("tel:" + phoneNumber));
  107. startActivity(intent);
  108. }
  109. });
  110. adapter.setOnItemChangesClickListener(new ListAdapter.onItemChangesListener() {
  111. @Override
  112. public void onChangesClick(int i) {
  113. Phone phone_check = phones.get(i);
  114. String checkName = phone_check.getName(),
  115. checkPhone1 = phone_check.getPhone1(),
  116. checkPhone2 = phone_check.getPhone2(),
  117. checkHousePhone = phone_check.getHouerPhone(),
  118. checkOfficePhone = phone_check.getOfficephone(),
  119. checkAddress = phone_check.getAddress(),
  120. checkRemark = phone_check.getRemark();
  121. Intent intent = new Intent(MainActivity.this, EditPhone.class);
  122. intent.putExtra("extra_name",checkName);
  123. intent.putExtra("extra_phone1",checkPhone1);
  124. intent.putExtra("extra_phone2",checkPhone2);
  125. intent.putExtra("extra_housePhone",checkHousePhone);
  126. intent.putExtra("extra_officePhone",checkOfficePhone);
  127. intent.putExtra("extra_address",checkAddress);
  128. intent.putExtra("extra_remark",checkRemark);
  129. intent.putExtra("extra_i",i);
  130. startActivity(intent);
  131. Toast.makeText(MainActivity.this,"编辑",Toast.LENGTH_SHORT).show();
  132. }
  133. });
  134. adapter.setOnItemMassgasClickListener(new ListAdapter.onItemMassgasListener() {
  135. @Override
  136. public void onMassgasClick(int i) {
  137. Phone phone_check = phones.get(i);
  138. String phoneNumber = phone_check.getPhone1();
  139. Intent intent = new Intent();
  140. intent.setAction(Intent.ACTION_VIEW);
  141. intent.setData(Uri.parse("smsto:" + phoneNumber));
  142. startActivity(intent);
  143. Toast.makeText(MainActivity.this,"短信",Toast.LENGTH_SHORT).show();
  144. }
  145. });
  146. }
  147. private void DeleteDialog(final int positon){
  148. AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
  149. builder.setMessage("删除联系人");
  150. builder.setTitle("提示");
  151. builder.setPositiveButton("删除", new DialogInterface.OnClickListener() {
  152. @Override
  153. public void onClick(DialogInterface dialogInterface, int i) {
  154. Phone phone_check = phones.get(positon);
  155. String checkName = phone_check.getName(),
  156. checkPhone1 = phone_check.getPhone1(),
  157. checkPhone2 = phone_check.getPhone2(),
  158. checkHousePhone = phone_check.getHouerPhone(),
  159. checkOfficePhone = phone_check.getOfficephone(),
  160. checkAddress = phone_check.getAddress(),
  161. checkRemark = phone_check.getRemark();
  162. phones.remove(positon);
  163. adapter.notifyDataSetChanged(); //更新listView
  164. db.delete("PhoneNumber","name = ? and phone1 = ? and phone2 = ? and housePhone = ? and officePhone = ? and address = ? and remark = ?",new String[]{ checkName,checkPhone1,checkPhone2,checkHousePhone,checkOfficePhone,checkAddress,checkRemark});
  165. Toast.makeText(MainActivity.this,"删除成功!",Toast.LENGTH_SHORT).show();
  166. }
  167. });
  168. builder.setNeutralButton("取消", new DialogInterface.OnClickListener() {
  169. @Override
  170. public void onClick(DialogInterface dialogInterface, int i) {
  171. }
  172. });
  173. builder.show();
  174. }
  175. }

小编其实也是个菜鸟,可以看出来大多数功能不过是投机取巧,同时好多地方并没有按照标准来写,只是为了能够实现这样的功能即可,纯属为了应付课程设计,早点回家过年。。。。。。

配置AndroidManifest.xml文件

之前提到过,我们需要调用系统 打电话和发短信功能,那么我们需要向系统申请权限,只有程序有权限之后我们才能实现打电话功能。具体配置为打开AndroidManifest.xml文件,在文件中添加如下代码:

  1. <uses-permission android:name="android.permission.CALL_PHONE"/>
  2. <uses-permission android:name="android.permission.READ_PHONE_STATE"/>

因为我们在程序中使用了汉字,所以我们需要在在这里插入图片描述
文件中加入这样的一行代码compileOptions.encoding = "UTF-8"
位置为如图所示的地方:
在这里插入图片描述
但我们做完所有的一切之后,我们的程序就达到了课程设计的要求,让我们来看看效果如何把

程序效果

添加联系人
在这里插入图片描述
查看联系人信息
在这里插入图片描述
编辑联系人信息
在这里插入图片描述
打电话功能
在这里插入图片描述
发送短信功能
在这里插入图片描述
监测是否存在用户和是否输入联系人和联系方式
在这里插入图片描述
长按删除联系人
在这里插入图片描述
到此为止,所有功能已经实现了哦!!!小编英文不好,有些变量名可能存在拼写错误,各位大佬多多包含,如果有帮助到你,记得给个赞,转发哦!!!

发表评论

表情:
评论列表 (有 0 条评论,651人围观)

还没有评论,来说两句吧...

相关阅读