Get contact name given a phone number in Android

I am trying to retrieve contact names given the contact phone number. I made a function that should work in all API versions, by I can't make it work in 1.6 and I can't see the problem, maybe someone can spot it? Note that, I've replaced the API constants for strings so I don't have deprecated warning problems. public String getContactName(final String phoneNumber) { Uri uri; String[] projection; if (Build.VERSION.SDK_INT >= 5) { uri = Uri.parse("content://com.android.contacts/phone_lookup"); projection = new String[] { "display_name" }; } else { uri = Uri.parse("content://contacts/phones/filter"); projection = new String[] { "name" }; } uri = Uri.withAppendedPath(uri, Uri.encode(phoneNumber)); Cursor cursor = this.getContentResolver().query(uri, projection, null, null, null); String contactName = ""; if (cursor.moveToFirst()) { contactName = cursor.getString(0); } cursor.close(); cursor = null; return contactName; }
Don't support 1.6 anymore! developer.android.com/resources/dashboard/…. It makes up for only 2.2% of the current user base and that number will shrink, shrink, shrink. It may never hit zero, but that's only because of technology laggards that aren't going to hear about your new bleeding edge app anyway! Don't waste your time!

以上就是Get contact name given a phone number in Android的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏