短信内容提供商和联系人之间的关系

发布于 2024-11-18 10:17:55 字数 203 浏览 5 评论 0原文

我有一个大问题,我在短信内容提供商和联系人内容提供商之间可以得到的唯一关系是电话号码,但是短信内容提供商以与联系人内容提供商中存储号码的方式不同的格式存储号码。因此,我如何比较两个表之间的数字,因为我没有看到任何其他关系或绑定它们的列。在我的国家,电话号码格式是 +254728306203,这是短信提供商存储号码的方式,但联系人提供商将其存储为 072-830-6203 任何帮助将不胜感激

I have a big problem, the only relationship i can get between sms content provider and the contacts content provider is the phone numbers BUT the sms content provider stores numbers in a different format as compared to how the numbers are stored in the contacts content provider. hence how can I compare the numbers between the two tables since I dont see any other relationship or column that binds them. I my country the phone number format is +254728306203, this is how the sms provider store the number but the contacts provider stores it as 072-830-6203 Any help will be greatly appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鸵鸟症 2024-11-25 10:17:55

试试这个(适用于 SDK 2.0+)。让数字采用任何格式。只需将其作为字符串传递...

在清单中添加权限 android.permission.READ_CONTACTS

/**
     * Retrieves display name for the provided contact number
     * 
     * @param context
     *            Context
     * @param number
     *            The contact number for which display name is to be retrieved
     *            form android contacts
     * @return Returns displayName for the contact if available. If display name
     *         is not available then it returns the same number
     */
    public static String getContactNameFromNumber(Context context, String number) {
        // If name is not found, number will be returned
        String contactDisplayName = number;

        Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,
                Uri.encode(number));
        Cursor cursor = context.getContentResolver().query(uri,
                new String[] { PhoneLookup.DISPLAY_NAME }, null, null, null);
        if (cursor.moveToFirst()) {
            contactDisplayName = cursor.getString(cursor
                    .getColumnIndex(PhoneLookup.DISPLAY_NAME));
        }
        cursor.close();
        Log.d("GetNumber", "Retrived DisplayName for contact number:" + number
                    + " DisplayName:" + contactDisplayName);

        return contactDisplayName;

    }

Try this (For SDK 2.0+). Let the number be in any format.. just pass it as a string...

Add permission android.permission.READ_CONTACTS in manifest.

/**
     * Retrieves display name for the provided contact number
     * 
     * @param context
     *            Context
     * @param number
     *            The contact number for which display name is to be retrieved
     *            form android contacts
     * @return Returns displayName for the contact if available. If display name
     *         is not available then it returns the same number
     */
    public static String getContactNameFromNumber(Context context, String number) {
        // If name is not found, number will be returned
        String contactDisplayName = number;

        Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,
                Uri.encode(number));
        Cursor cursor = context.getContentResolver().query(uri,
                new String[] { PhoneLookup.DISPLAY_NAME }, null, null, null);
        if (cursor.moveToFirst()) {
            contactDisplayName = cursor.getString(cursor
                    .getColumnIndex(PhoneLookup.DISPLAY_NAME));
        }
        cursor.close();
        Log.d("GetNumber", "Retrived DisplayName for contact number:" + number
                    + " DisplayName:" + contactDisplayName);

        return contactDisplayName;

    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文