Skip to content

Instantly share code, notes, and snippets.

@ameerhamza6733
Created October 25, 2018 18:15
Show Gist options
  • Save ameerhamza6733/20dac02db86ecb0e2c1030b915af8b0c to your computer and use it in GitHub Desktop.
Save ameerhamza6733/20dac02db86ecb0e2c1030b915af8b0c to your computer and use it in GitHub Desktop.
private class myRecipientCallingNumberFinder extends AsyncTask<Void, Void, Void> {
private String Queary;
boolean isRecipientNumberFound = false;
private List<String> mNameListFounded = new ArrayList<>();
public myRecipientCallingNumberFinder(String queary) {
Queary = queary;
}
@Override
protected Void doInBackground(Void... params) {
try {
Log.d("callingActivty", "requiredName=" + Queary);
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
null, null, null, null);
if (cur.getCount() > 0) {
while (cur.moveToNext()) {
String id = cur.getString(
cur.getColumnIndex(ContactsContract.Contacts._ID));
String name = cur.getString(cur.getColumnIndex(
ContactsContract.Contacts.DISPLAY_NAME));
Log.d("callingActivty", "Name from phone Book " + name);
if (Queary.toLowerCase().contains(name.toLowerCase())) {
Log.d("callingActivty", "requiredName found" + name);
mNameListFounded.add(name);
isRecipientNumberFound = true;
}
if (cur.getInt(cur.getColumnIndex(
ContactsContract.Contacts.HAS_PHONE_NUMBER)) > 0) {
Cursor pCur = cr.query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?",
new String[]{id}, null);
while (pCur.moveToNext()) {
String phoneNo = pCur.getString(pCur.getColumnIndex(
ContactsContract.CommonDataKinds.Phone.NUMBER));
mHashMapContacts.put(name, phoneNo);
}
pCur.close();
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
try {
if(newIntance!=null)
getSupportFragmentManager().beginTransaction().remove(newIntance).commitAllowingStateLoss();
if (isRecipientNumberFound) {
updateUI();
} else {
myTextToSpeech.intiTextToSpeech(CallingActivity.this, "hi", getResources().getString(R.string.Sorry_App_Kasy_Call_karna_Chaatay_Ha));
showVoiceRegonizerDiloge("en-IN");
isRecipientNumberFound = false;
}
} catch (Exception s) {
// Toast.makeText(CallingActivity.this, "Exception:" + s.getMessage(), Toast.LENGTH_LONG).show();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment