这是对我自己的回答。当然,您需要在清单中获得许可。
cr = activity:getContentResolver()
contacts = luajava.bindClass("android.provider.ContactsContract")
build = luajava.bindClass("android.os.Build")
D_Name = build.VERSION.SDK_INT >= build.VERSION_CODES.HONEYCOMB and contacts.Contacts.DISPLAY_NAME_PRIMARY or contacts.Contacts.DISPLAY_NAME
--str = luajava.bindClass("java.lang.String")
cur = cr:query(contacts.Contacts.CONTENT_URI)
local count = cur and cur:getCount() or -1
print(count)
if cur and count > 0 then
--local name, id, pCur, phoneNo
while cur:moveToNext() do
id = cur:getString(cur:getColumnIndex(contacts.Contacts._ID))
name = cur:getString(cur:getColumnIndex(D_Name))
--print("id: " .. id, "name: " .. name)
if cur:getInt(cur:getColumnIndex(contacts.Contacts.HAS_PHONE_NUMBER)) > 0 then
--str_str = luajava.newInstance( "java.lang.String", id )
-- str_array = luajava.newInstance( "java.lang.reflect.Array", ({str_str}) )
pCur = cr:query(contacts.CommonDataKinds.Phone.CONTENT_URI, nil, contacts.CommonDataKinds.Phone.CONTACT_ID .. " = ?", ({id}), nil)
print(pCur:getCount())
while pCur:moveToNext() do
phoneNo = pCur:getString(pCur:getColumnIndex(contacts.CommonDataKinds.Phone.NUMBER))
print("Name: " .. name, "Phone Number: " .. phoneNo)
end
pCur:close()
end
--if cur:getInt(cur:getColumnIndex(contacts.Contacts.HAS_EMAIL_DATA)) > 0 then
--str_str = luajava.newInstance( "java.lang.String", id )
-- str_array = luajava.newInstance( "java.lang.reflect.Array", ({str_str}) )
pCur = cr:query(contacts.CommonDataKinds.Email.CONTENT_URI, nil, contacts.CommonDataKinds.Email.CONTACT_ID .. " = ?", ({id}), nil)
print(pCur:getCount())
if pCur then
while pCur:moveToNext() do
Email_data = pCur:getString(pCur:getColumnIndex(contacts.CommonDataKinds.Email.DATA))
print("Name: " .. name, "Email_data: " .. Email_data)
end
end
pCur:close()
pCur = cr:query(contacts.Data.CONTENT_URI, nil, contacts.Data.CONTACT_ID .. " = " .. id)
print(pCur:getCount())
if pCur then
while pCur:moveToNext() do
skype_type = pCur:getInt(pCur:getColumnIndex(contacts.CommonDataKinds.Im.PROTOCOL))
print(skype_type, contacts.CommonDataKinds.Im.PROTOCOL_SKYPE)
if contacts.CommonDataKinds.Im.PROTOCOL_SKYPE == skype_type then
imName = pCur:getString(pCur:getColumnIndex(contacts.CommonDataKinds.Im.DATA))
print("Name: " .. name, "skype_type: " .. skype_type .. "imName: " .. imName)
end
end
end
pCur:close()
--end
end
end
if cur then
cur:close()
end