皮皮网

【小程序制作源码】【返利网接单源码】【视频影视源码app】android 通讯录 源码

时间:2025-01-23 23:22:35 来源:微博对接源码

1.android ͨѶ¼ Դ?讯录?

android 通讯录 源码

android ͨѶ¼ Դ??

       1. Modify the `getTelClick()` method:

        - Change the method name from `getTelClick` to `onGetTelClick` for better readability and adherence to naming conventions.

        - Ensure that the method signature is correct and that it is properly calling the new method.

       2. Modify the Toast breadcrumb提示:

        - Remove the unnecessary string concatenation within the Toast message.

        - Use string resources for the Toast message to improve localization support.

       3. Modify the method for获取联系人名字:

        - Correct the column index for the contact's name to match the correct field from the ContactsContract.

       4. Adjust the location slightly:

        - Ensure that the code for finding the contact's phone number is inside the correct `if` block to avoid unnecessary queries.

       Here is the modified section of the code:

       ```java

       // ... (previous code)

       @Override

       protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_phone_name);

        et = (EditText) this.findViewById(R.id.mobile);

       }

       public void onGetTelClick(View view) {

        String name = et.getText().toString().trim();

        getContactNumber(name);

       }

       /

**

        * 通过输入的姓名获取电话号码

        */

       public void getContactNumber(String name) {

        // 使用ContentResolver查找联系人数据

        Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);

        // 遍历查询结果,找到所需号码

        while (cursor.moveToNext()) {

        // 获取联系人ID

        String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));

        // 获取联系人的源码小程序制作源码名字

        String contactName = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));

        if (name.equals(contactName)) {

        // 使用ContentResolver查找联系人的电话号码

        Cursor phone = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[]{ contactId}, null);

        if (phone.moveToNext()) {

        String phoneNumber = phone.getString(phone.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));

        Toast.makeText(this, phoneNumber, Toast.LENGTH_SHORT).show(); // Use string resource for the message

        Log.d(TAG, "电话:" + phoneNumber);

        break;

        }

        }

        }

       }

       ```

       Ensure that you have defined a string resource for the Toast message in your `res/values/strings.xml` file, like this:

       ```xml

        电话号码:%1$s

       ```

       And use it in the Toast.makeText method as shown above.

推荐资讯
点题整治、你我同查 福建各地同步突击检查校园食堂及配餐企业

点题整治、你我同查 福建各地同步突击检查校园食堂及配餐企业

陕西西安新城区:加强节日期间疫情防控和市场秩序检查

陕西西安新城区:加强节日期间疫情防控和市场秩序检查

山东济南市场监管部门的年味:“全程帮”让外商投资企业感受服务的速度与温情

山东济南市场监管部门的年味:“全程帮”让外商投资企业感受服务的速度与温情

巴黎奧運倒計時6天|話題女王吳艷妮 飛躍巴黎展英姿

巴黎奧運倒計時6天|話題女王吳艷妮 飛躍巴黎展英姿

山东商河:聚焦三个坚持消费环境持续向好

山东商河:聚焦三个坚持消费环境持续向好

新春走基层|查干湖畔有一群“最可爱的人”

新春走基层|查干湖畔有一群“最可爱的人”

copyright © 2016 powered by 皮皮网   sitemap