[Galaxy S 4 i9505 Android Development] chenxiaolong:
EDIT: If anyone knows of any good phone number lookup service/website, please let me know. I will support Google (regular and reverse lookup and OpenStreetMap (regular lookup), but I can add more.

Just finished getting reverse lookup working on the dialer :) Just need to change it to do the lookup on Google's servers now.

The way it works is the dialer will lookup the phone number for an incoming call and then cache the details. The information will be accessible like a regular contact. This is almost the same implementation as the Google Dialer, but I will be extending the feature to support more than just Google's databases ;)

Here are some screenshots of it looking up phone numbers on a server I hacked up.

Code for the useless Homer Simpson reverse lookup server (written in Python 3; depends on https://github.com/daviddrysdale/python-phonenumbers)

#!/usr/bin/env python3

import http.server
import urllib.parse

import json
import phonenumbers

port = 8000

class ReverseLookupRequestHandler(http.server.BaseHTTPRequestHandler):
protocol_version = 'HTTP/1.1'

def do_GET(self):
queries = urllib.parse.parse_qs(urllib.parse.urlparse(self.path).query)
phonenumber = queries['id'][0]

print('Got request for phone number: ' + phonenumber)
print('--- Headers begin ---')
print(self.headers)
print('--- Headers end ---')

json = self.generate_json(phonenumber)

self.send_response(200)

self.send_header('Cache-Control',
'private, max-age=0, must-revalidate, no-transform')
self.send_header('ETag', 'DUMMY')
self.send_header('Content-Type', 'application/json; charset=UTF-8')
self.send_header('X-Content-Type-Options', 'nosniff')
self.send_header('X-Frame-Options', 'SAMEORIGIN')
self.send_header('X-XSS-Protection', '1; mode=block')
self.send_header('Content-Length', len(json))
self.send_header('Server', 'GSE')
self.send_header('Alternate-Protocol', '443:quic')

self.end_headers()

self.wfile.write(bytes(json, "UTF-8"))

def generate_json(self, phonenumber):
pn = phonenumbers.parse(phonenumber)
pn_national = phonenumbers.format_number(pn,
phonenumbers.PhoneNumberFormat.NATIONAL)
pn_international = phonenumbers.format_number(pn,
phonenumbers.PhoneNumberFormat.INTERNATIONAL)

image = 'http://static.tvtropes.org/pmwiki/pub/images/homer-simpson-5_4255.jpg'

data = {
'kind': 'plus#peopleList',
'items': [{
'metadata': {
'objectType': 'page',
'plusPageType': 'local'
},
'names': [{
# 'displayName': '(Debug) Call from ' + pn_national,
'displayName': '(Debug) Homer Simpson',
'familyName': '.',
'givenName': '(Debug) Call from ' + pn_national,
'metadata': {
'container': 'place'
}
}],
'urls': [{
'value': 'http://www.thesimpsons.com/'
}, {
'value': 'https://www.google.com/'
}],
'images': [{
'url': image,
'metadata': {
'container': 'place'
}
}],
'phoneNumbers': [{
'value': pn_national,
'type': 'main',
'formattedType': 'Main'
}, {
'value': pn_international,
'type': 'other',
'formattedType': 'Other'
}],
'addresses': [{
'value': '742 Evergreen Terrace, Springfield, OR, United States'
}]
}]
}
return json.dumps(data, indent=2)

httpd = http.server.HTTPServer(("", port), ReverseLookupRequestHandler)
print("Serving on port", port)
httpd.serve_forever()

PYTHONPATH=/path/to/python-phonenumbers/python/ python3 ReverseLookupServer.py