Created
August 30, 2018 11:38
-
-
Save sukso96100/6c341f4850fb368ef924a0a72a600d22 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.youngbin.assistscreen.util; | |
import android.content.ContentUris; | |
import android.content.Context; | |
import android.database.Cursor; | |
import android.graphics.Bitmap; | |
import android.graphics.BitmapFactory; | |
import android.net.Uri; | |
import android.provider.ContactsContract; | |
import java.io.InputStream; | |
/** | |
* Created by youngbin on 14. 7. 12. | |
*/ | |
public class ContactUtil { | |
private Context mContext; | |
private String PhoneNumber; | |
private String ContactName; | |
private String ContactId; | |
private Bitmap ContactImage; | |
private InputStream IS; | |
private Cursor cursor; | |
public ContactUtil(Context context, String phonenumber){ | |
mContext = context; | |
PhoneNumber = phonenumber; | |
Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phonenumber)); | |
//Things to Access | |
String[] projection = new String[] { | |
ContactsContract.PhoneLookup.DISPLAY_NAME, | |
ContactsContract.PhoneLookup._ID}; | |
cursor = mContext.getContentResolver().query(uri, projection, null, null, null); | |
if (cursor.moveToFirst()) { | |
ContactId = cursor.getString(cursor.getColumnIndex(ContactsContract.PhoneLookup._ID)); | |
ContactName = cursor.getString(cursor.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME)); | |
// Get photo of contactId as input stream: | |
Uri contacturi = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, Long.parseLong(ContactId)); | |
IS = ContactsContract.Contacts.openContactPhotoInputStream(context.getContentResolver(), contacturi); | |
}else{} | |
} | |
public String getContactName(){ | |
return ContactName; | |
} | |
public Bitmap getContactImage() { | |
ContactImage = BitmapFactory.decodeStream(IS); | |
return ContactImage; | |
} | |
public void close(){ | |
cursor.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment