I want to fetch contacts and store them to a list. I can see my contact names and phones in the listView but image view is empty for all contacts.
How can I get Images?
I have a Fragment with a listView to show contacts.
This is my main fragment:
private List<AddressBookContact> getContacts() {
List<AddressBookContact> list = new LinkedList<>();
LongSparseArray<AddressBookContact> array = new LongSparseArray<>();
long start = System.currentTimeMillis();
String[] projection = {
ContactsContract.Data.MIMETYPE,
ContactsContract.Data.CONTACT_ID,
ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Contactables.DATA,
ContactsContract.CommonDataKinds.Contactables.TYPE,
};
String selection = ContactsContract.Data.MIMETYPE + " in (?, ?)";
String[] selectionArgs = {
ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE,
ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE,
};
String sortOrder = ContactsContract.Contacts.SORT_KEY_ALTERNATIVE;
Uri uri = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
uri = ContactsContract.CommonDataKinds.Contactables.CONTENT_URI;
} else {
uri = ContactsContract.Data.CONTENT_URI;
}
// we could also use Uri uri = ContactsContract.Data.CONTENT_URI;
// ok, let's work...
Cursor cursor = getContext().getContentResolver().query(uri, projection, selection, selectionArgs, sortOrder);
final int mimeTypeIdx = cursor.getColumnIndex(ContactsContract.Data.MIMETYPE);
final int idIdx = cursor.getColumnIndex(ContactsContract.Data.CONTACT_ID);
final int nameIdx = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
final int dataIdx = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Contactables.DATA);
final int typeIdx = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Contactables.TYPE);
while (cursor.moveToNext()) {
long id = cursor.getLong(idIdx);
AddressBookContact addressBookContact = array.get(id);
if (addressBookContact == null) {
addressBookContact = new AddressBookContact(
id, cursor.getString(nameIdx), getResources(), openPhoto(idIdx));
array.put(id, addressBookContact);
list.add(addressBookContact);
}
int type = cursor.getInt(typeIdx);
String data = cursor.getString(dataIdx);
String mimeType = cursor.getString(mimeTypeIdx);
if (mimeType.equals(ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)) {
// mimeType == ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE
addressBookContact.addEmail(type, data);
} else {
// mimeType == ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE
addressBookContact.addPhone(type, data);
}
}
cursor.close();
return list;
}
Related
I want to load cover audio art in android for show list of audio from device. For this purpose i used this following Link:
way1
way2
way3
Like following picture:
And my code for Load audio files:
private void loadAudio() {
ContentResolver contentResolver = getContentResolver();
Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
String selection = MediaStore.Audio.Media.IS_MUSIC + "!= 0";
String sortOrder = MediaStore.Audio.Media.TITLE + " ASC";
Cursor cursor = contentResolver.query(uri, null, selection, null, sortOrder);
if (cursor != null && cursor.getCount() > 0) {
audioList.clear();
while (cursor.moveToNext()) {
String data = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DATA));
String title = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.TITLE));
String album = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM));
String artist = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST));
int albumId = cursor.getInt(cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID));
Cursor cursor1 = contentResolver.query(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,
new String[]{MediaStore.Audio.Albums._ID, MediaStore.Audio.Albums.ALBUM_ART},
MediaStore.Audio.Albums._ID + "=" + albumId, null, null);
Bitmap bitmap = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {
try {
bitmap = contentResolver.loadThumbnail(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, new Size(30, 30), null);
} catch (IOException e) {
e.printStackTrace();
}
}
String albumArt = "";
if (cursor1 != null && cursor1.getCount() > 0)
while (cursor1.moveToNext()) {
albumArt = cursor.getString(cursor1.getColumnIndex(MediaStore.Audio.Albums.ALBUM_ART));
}
// Save to audioList
audioList.add(new Audio(data, title, album, artist, albumArt, bitmap));
}
}
cursor.close();
setAdapter();
}
And in MyAdapter about recyclerview:
#Override
public void onBindViewHolder(#NonNull MainHolder holder, int position) {
Audio audio = arrayList.get(position);
holder.txtTitle.setText("Title: " + audio.getTitle());
holder.txtAlbum.setText("Album: " + audio.getAlbum());
holder.txtArtist.setText("Artist: " + audio.getArtist());
File imgFile = new File(audio.getAlbumArt());
Picasso.get().load(imgFile.getAbsolutePath()).into(holder.img);
if (imgFile.exists()) {
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
holder.img.setImageBitmap(myBitmap);
}
}
Help me please.
Solved:
Load audio file:
private void loadAudio() {
ContentResolver contentResolver = getContentResolver();
Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
String selection = MediaStore.Audio.Media.IS_MUSIC + "!= 0";
String sortOrder = MediaStore.Audio.Media.ARTIST + " DESC";
Cursor cursor = contentResolver.query(uri, null, selection, null, sortOrder);
if (cursor != null && cursor.getCount() > 0) {
audioList.clear();
while (cursor.moveToNext()) {
Audio audio = new Audio();
String data = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DATA));
String title = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.TITLE));
String album = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM));
String artist = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST));
int albumId = cursor.getInt(cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID));
Bitmap thumbnail = null;
String albumArt = null;
Uri imageUri_t;
Cursor cursor1 = contentResolver.query(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,
new String[]{MediaStore.Audio.Albums._ID, MediaStore.Audio.Albums.ALBUM_ART},
MediaStore.Audio.Albums._ID + "=" + albumId, null, null);
while (cursor1.moveToNext()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
Size thumbSize = new Size(100, 100);
try {
int thumbColumn = cursor1.getColumnIndexOrThrow(MediaStore.Audio.Albums._ID);
int _thumpId = cursor1.getInt(thumbColumn);
imageUri_t = ContentUris.withAppendedId(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, _thumpId);
thumbnail = getContentResolver().loadThumbnail(imageUri_t, thumbSize, null);
} catch (IOException e) {
e.printStackTrace();
}
} else {
albumArt = cursor1.getString(cursor1.getColumnIndex(MediaStore.Audio.Albums.ALBUM_ART));
}
}
audio.setData(data);
audio.setTitle(title);
audio.setAlbum(album);
audio.setArtist(artist);
audio.setAlbumId(albumId);
audio.setAlbumArt(albumArt);
audio.setThumbnail(thumbnail);
audioList.add(audio);
}
}
cursor.close();
setAdapter();
}
And a part of MyAdapter:
#Override
public void onBindViewHolder(#NonNull MainHolder holder, int position) {
Audio audio = arrayList.get(position);
holder.txtTitle.setText("Title: " + audio.getTitle());
holder.txtAlbum.setText("Album: " + audio.getAlbum());
holder.txtArtist.setText("Artist: " + audio.getArtist());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
if (audio.getThumbnail() != null)
holder.img.setImageBitmap(audio.getThumbnail());
} else {
if (audio.getAlbumArt() != null) {
File imgFile = new File(audio.getAlbumArt());
if (imgFile.exists()) {
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
holder.img.setImageBitmap(myBitmap);
}
}
}
}
First query on MediaStore.Audio.Media.ARTIST about fetch audio info from MediaStore.
There is a difference About fetch thumbnail of Audio file in android 10 (Q) and below.
So query for lower than Android 10 is like follow:
String albumArt = cursor1.getString(cursor1.getColumnIndex(MediaStore.Audio.Albums.ALBUM_ART));
You can get album art from ALBUM_ART column in MediaStore.Audio.Albums.
Then for Android 10 like follow this:
Query on MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI where albumId equals _ID column from MediaStore.Audio.Albums.
And load thumbnail from Content Resolver by image uri...
I hope it is useful ;)
I was trying to get songs from album in my app. I wrote code below with some help on internet but now I'm getting all items as 0. I dont know why I'm getting 0.
public void songs()
{
String name;
long genreId;
Uri uri;
Cursor genrecursor;
Cursor tempcursor;
String[] proj1 = { android.provider.MediaStore.Audio.Albums._ID,
android.provider.MediaStore.Audio.Albums.ALBUM};
String[] proj2 = {MediaStore.Audio.Media.DISPLAY_NAME,MediaStore.Audio.Media.ALBUM_ID
,MediaStore.Audio.Media.DATA};
genrecursor = managedQuery(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, proj1, null, null, null);
if (genrecursor.moveToFirst()) {
do {
name = String.valueOf(genrecursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ALBUM));
Log.i("Tag-album name", genrecursor.getString(Integer.parseInt(name)));
name = String.valueOf(genrecursor.getColumnIndexOrThrow(MediaStore.Audio.Albums._ID));
genreId = Long.parseLong(genrecursor.getString(Integer.parseInt(name)));
uri = MediaStore.Audio.Genres.Members.getContentUri("external", genreId);
tempcursor = managedQuery(uri, proj2, null, null, null);
Log.i("Tag-Number of songs for this album", tempcursor.getCount() + "");
if (tempcursor.moveToFirst()) {
do {
name = String.valueOf(tempcursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DISPLAY_NAME));
String art = String.valueOf(tempcursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM_ID));
String path = String.valueOf(tempcursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA));
Log.i("Tag-Song name", tempcursor.getString(Integer.parseInt(name)));
albumInfo s = new albumInfo(name,art,path);
albumSongList.add(s);
} while (tempcursor.moveToNext());
}
} while (genrecursor.moveToNext());
}
}
i did this.
Uri uri= MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI;
String[] columns = {
MediaStore.Audio.Albums.ALBUM};
Cursor cursor =getApplicationContext().getContentResolver().
query(uri, columns, null,
null, null);
if (cursor != null && cursor.moveToFirst()) {
do {
Log.v("bbb",
cursor.getString(cursor
.getColumnIndex(MediaStore.Audio.Albums.ALBUM)));
v=cursor.getString(cursor
.getColumnIndex(MediaStore.Audio.Albums.ALBUM));
} while (cursor.moveToNext());
}
// I want to list down song in album Rolling Papers (Deluxe Version)
String[] column = { MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.ALBUM_ID,
MediaStore.Audio.Media.DISPLAY_NAME,
};
Intent i=getIntent();
final String value=i.getStringExtra("sol");
String [] x=new String[]{value};
String where = MediaStore.Audio.Albums.ALBUM + "=?";
Log.e("syn",v);
String whereVal[] = {v};
String orderBy = android.provider.MediaStore.Audio.Media.TITLE;
cursor =getApplicationContext().getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
column, where, x,null);
if (cursor != null && cursor.moveToFirst()) {
do {
Log.v("Vipul",
cursor.getString(cursor
.getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME)));
String name=cursor.getString(cursor
.getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME));
String art=cursor.getString(cursor
.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID));
String path=cursor.getString(cursor
.getColumnIndex(MediaStore.Audio.Media.DATA));
albumInfo s = new albumInfo(name,art,path); // EXCLUDED
albumSongList.add(s);
} while (cursor.moveToNext());
}
}
public static ArrayList<Song> getPlaylistcontent(Context context,
long playlistID) {
ArrayList<Song> songs = new ArrayList<Song>();
final String idString = MediaStore.Audio.Playlists.Members._ID;
final String dataString = MediaStore.Audio.Playlists.Members.DATA;
String[] projection = new String[] { idString, dataString };
Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external",
playlistID);
Cursor cursor = context.getContentResolver().query(uri, projection,
null, null, null);
if (cursor != null && cursor.moveToFirst()) {
do {
final String id = cursor.getString(cursor
.getColumnIndex(idString));
final String path = cursor.getString(cursor
.getColumnIndex(dataString));
Song song = getSong(context, path);
if (song != null) {
songs.add(song);
Log.d("MyTAG", song.getName());
}
} while (cursor.moveToNext());
}
return songs;
}
public static ArrayList<Playlist> getAllPlaylists(Context context) {
return helper_getPlaylists(context, null);
}
private static ArrayList<Playlist> helper_getPlaylists(Context context,
String selection) {
ArrayList<Playlist> playlists = new ArrayList<Playlist>();
final String idString = MediaStore.Audio.Playlists._ID;
final String nameString = MediaStore.Audio.Playlists.NAME;
Uri externalUri = MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI;
String projection[] = new String[] { idString, nameString };
// sort by date added
String sortOrder = MediaStore.Audio.Playlists.DATE_ADDED;
Cursor audioCursor = context.getContentResolver().query(externalUri,
projection, selection, null, sortOrder);
if (audioCursor != null && audioCursor.moveToFirst()) {
do {
final String id = audioCursor.getString(audioCursor
.getColumnIndex(idString));
final String name = audioCursor.getString(audioCursor
.getColumnIndex(nameString));
Playlist playlist = new Playlist();
playlist.setName(name);
playlist.setID(id);
playlists.add(playlist);
} while (audioCursor.moveToNext());
}
return playlists;
}
These are 2 (3) methods I use to get the playlist content. Well, they should return the playlist content but it doesn't. The method getSong() works 100% and is not the problem. I use it few thousand times in another part of my program and it is fast and also reviewed on code-review.
I call getAllPlaylists() in the main activity, display these playlists in a ListView and when I click on one item, I will start a new activity which should display the items of that playlist. So I pass the clicked playlist's ID through an intent and use it in the new activity (works and I do get the correct ID's).
//MainActivity
Arraylist<Playlist> playlists = MediaManager.getAllPlaylists( this );
//New Activity
long playlistID = getIntent().getExtras().getLong("playlist_id"); //works.
//in an asynctask in new activity
Arraylist<Song> playlistContent = MediaManager.getPlaylistContent( this, playlistID ); //is empty
This is driving me crazy! What did I do wrong?
If I am correct, the intent to get playlist details works, you get the _ids but you do not get the songs. Remember that the _id is the id of the line of each playlist item, NOT the audio_id. I struggled with this for a while. Perhaps this was your issue.
This is how I resolved it:
public Cursor getPlaylistTracks(Context context, Long playlist_id) {
Uri newuri = MediaStore.Audio.Playlists.Members.getContentUri(
"external", playlist_id);
ContentResolver resolver = context.getContentResolver();
String _id = MediaStore.Audio.Playlists.Members._ID;
String audio_id = MediaStore.Audio.Playlists.Members.AUDIO_ID;
String artist = MediaStore.Audio.Playlists.Members.ARTIST;
String album = MediaStore.Audio.Playlists.Members.ALBUM;
String album_id = MediaStore.Audio.Playlists.Members.ALBUM_ID;
String title = MediaStore.Audio.Playlists.Members.TITLE;
String duration = MediaStore.Audio.Playlists.Members.DURATION;
String location = MediaStore.Audio.Playlists.Members.DATA;
String composer = MediaStore.Audio.Playlists.Members.COMPOSER;
String playorder = MediaStore.Audio.Playlists.Members.PLAY_ORDER;
String date_modified = MediaStore.Audio.Playlists.Members.DATE_MODIFIED;
String[] columns = { _id, audio_id, artist, album_id,album, title, duration,
location, date_modified, playorder, composer };
Cursor cursor = resolver.query(newuri, columns, null, null, null);
return cursor;
}
I've tried to make a gallery out of the Videos created with my app.
When I click on one of the Thumbnail pictures I want to save the selected Video in my preferences.
To get the Thumbnails I wrote following code:
public void addVidsToArray()
{
String[] projection = { MediaStore.Video.Media._ID };
String selection = MEDIA_DATA + " like ? ";
String [] selectionArgs = new String[] {"%Bla%"};
int columIndex;
int id;
Cursor videoCursor = managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
projection,
selection,
selectionArgs,
null);
videoCursor.moveToFirst();
if(videoCursor.getCount() >= 1)
{
while (videoCursor.moveToNext()) {
columIndex = videoCursor.getColumnIndexOrThrow(MediaStore.Video.Media._ID) ;
id = videoCursor.getInt(columIndex);
bitmaps.add(getThumbnail(id));
}
}
}
public Bitmap getThumbnail(int id)
{
ContentResolver crThumb = getContentResolver();
BitmapFactory.Options options=new BitmapFactory.Options();
options.inSampleSize = 1;
Bitmap curThumb = MediaStore.Video.Thumbnails.getThumbnail(crThumb, id, MediaStore.Video.Thumbnails.MICRO_KIND, options);
curThumb = Bitmap.createScaledBitmap(curThumb, 300, 300, false);
return curThumb;
}
I get the Tumbnail Pics due to the Uri id.
Now my Problem is how to bring that back to a normal path in a new File to saved it.
Following code is the the onClickListener which should save the video to the preferences.
But if I add the Uri to the new File, the file doesen't exsist.
I don't get it.
ga.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position, long id)
{
String[] projection = { MediaStore.Video.Media._ID };
String selection = MEDIA_DATA + " like ? ";
String [] selectionArgs = new String[] {"%Bla%"};
int columIndex;
int id1;
Cursor videoCursor = managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
projection,
selection,
selectionArgs,
null);
videoCursor.moveToFirst();
if(videoCursor.getCount() >= 1)
{
while (videoCursor.moveToNext()) {
columIndex = videoCursor.getColumnIndexOrThrow(MediaStore.Video.Media._ID) ;
id1 = videoCursor.getInt(columIndex);
daten.add(id1+"");
}
}
Log.v("vid id", ""+daten.get(position));
int idData = Integer.parseInt(daten.get(position));
saveVideo(idData);
}
});
}
public void saveVideo(int idData)
{
String uriString = "content://media/external/video/media/" + idData;
Uri uri = Uri.parse(uriString);
File mVideoFile = new File(uriString);
Log.v("testpfad", ""+ mVideoFile.getAbsolutePath() + " " + mVideoFile.getParentFile().getAbsolutePath() + " " + mVideoFile.exists());
mVideoFileLen = getDurationFromURI(uri);
//setPreferences(mVideoFile.getAbsolutePath(), PICKED_VIDEO);
//setPreferences(mVideoFileLen, VIDEO_LEN);
//startActivity(new Intent(this, Finished.class));
}
In the end I need to create a File with the help of the Id from the Uri.
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;
}
This seems to work fine in the latest versions:
private String getContactName(Context context, String number) {
String name = null;
// define the columns I want the query to return
String[] projection = new String[] {
ContactsContract.PhoneLookup.DISPLAY_NAME,
ContactsContract.PhoneLookup._ID};
// encode the phone number and build the filter URI
Uri contactUri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
// query time
Cursor cursor = context.getContentResolver().query(contactUri, projection, null, null, null);
if(cursor != null) {
if (cursor.moveToFirst()) {
name = cursor.getString(cursor.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME));
Log.v(TAG, "Started uploadcontactphoto: Contact Found # " + number);
Log.v(TAG, "Started uploadcontactphoto: Contact name = " + name);
} else {
Log.v(TAG, "Contact Not Found # " + number);
}
cursor.close();
}
return name;
}
Use reflections instead of comparing sdk version.
public String getContactName(final String phoneNumber)
{
Uri uri;
String[] projection;
mBaseUri = Contacts.Phones.CONTENT_FILTER_URL;
projection = new String[] { android.provider.Contacts.People.NAME };
try {
Class<?> c =Class.forName("android.provider.ContactsContract$PhoneLookup");
mBaseUri = (Uri) c.getField("CONTENT_FILTER_URI").get(mBaseUri);
projection = new String[] { "display_name" };
}
catch (Exception e) {
}
uri = Uri.withAppendedPath(mBaseUri, 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;
}
public static String getContactName(Context context, String phoneNumber)
{
ContentResolver cr = context.getContentResolver();
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber));
Cursor cursor = cr.query(uri, new String[]{PhoneLookup.DISPLAY_NAME}, null, null, null);
if (cursor == null)
{
return null;
}
String contactName = null;
if(cursor.moveToFirst())
{
contactName = cursor.getString(cursor.getColumnIndex(PhoneLookup.DISPLAY_NAME));
}
if(cursor != null && !cursor.isClosed()) {
cursor.close();
}
return contactName;
}
private String getContactNameFromNumber(String 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())
{
name = cursor.getString(cursor.getColumnIndex(PhoneLookup.D