Android: How to search through call logs for a specific number
I have function that collects all call logs, Incoming, outgoing and missed. It also gives me the call duration, date, type and time.
I want to search through this Call log for a specific number, "12345678".
Function:
StringBuffer sb = new StringBuffer();
Cursor managedCursor = getContentResolver().query(CallLog.Calls.CONTENT_URI, null, null, null, null);
int snumber = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE);
int date = managedCursor.getColumnIndex(CallLog.Calls.DATE);
int duration = managedCursor.getColumnIndex(CallLog.Calls.DURATION);
sb.append("Call Log :");
String phNumber = null;
while (managedCursor.moveToNext()) {
phNumber = managedCursor.getString(snumber);
String callType = managedCursor.getString(type);
String callDate = managedCursor.getString(date);
Date callDayTime = new Date(Long.valueOf(callDate));
String callDuration = managedCursor.getString(duration);
String dir = null;
int dircode = Integer.parseInt(callType);
switch (dircode) {
case CallLog.Calls.OUTGOING_TYPE:
dir = "OUTGOING";
break;
case CallLog.Calls.INCOMING_TYPE:
dir = "INCOMING";
break;
case CallLog.Calls.MISSED_TYPE:
dir = "MISSED";
break;
}
sb.append("nPhone Number:--- " + phNumber +
" nCall Type:--- " + dir +
" nCall Date:--- " + callDayTime +
" nCall duration in sec :--- " +
callDuration);
sb.append("n----------------------------------");
}
System.out.println(phNumber);
Just wondering how I would do this?
Appreciate any suggestions or answers!
java android
|
show 2 more comments
I have function that collects all call logs, Incoming, outgoing and missed. It also gives me the call duration, date, type and time.
I want to search through this Call log for a specific number, "12345678".
Function:
StringBuffer sb = new StringBuffer();
Cursor managedCursor = getContentResolver().query(CallLog.Calls.CONTENT_URI, null, null, null, null);
int snumber = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE);
int date = managedCursor.getColumnIndex(CallLog.Calls.DATE);
int duration = managedCursor.getColumnIndex(CallLog.Calls.DURATION);
sb.append("Call Log :");
String phNumber = null;
while (managedCursor.moveToNext()) {
phNumber = managedCursor.getString(snumber);
String callType = managedCursor.getString(type);
String callDate = managedCursor.getString(date);
Date callDayTime = new Date(Long.valueOf(callDate));
String callDuration = managedCursor.getString(duration);
String dir = null;
int dircode = Integer.parseInt(callType);
switch (dircode) {
case CallLog.Calls.OUTGOING_TYPE:
dir = "OUTGOING";
break;
case CallLog.Calls.INCOMING_TYPE:
dir = "INCOMING";
break;
case CallLog.Calls.MISSED_TYPE:
dir = "MISSED";
break;
}
sb.append("nPhone Number:--- " + phNumber +
" nCall Type:--- " + dir +
" nCall Date:--- " + callDayTime +
" nCall duration in sec :--- " +
callDuration);
sb.append("n----------------------------------");
}
System.out.println(phNumber);
Just wondering how I would do this?
Appreciate any suggestions or answers!
java android
1
Post your function
– Arahasya
Nov 12 at 19:17
@Arahasya, posted function
– magicmass
Nov 12 at 19:45
1
It sounds like you're on the right track: 1) Format "target number" PhoneNumberUtils to match the locale in your database, then, 2) in your loop, check if "targetNumber" equals "phNumber".
– paulsm4
Nov 12 at 19:59
Hi, thanks for the help! What do you mean by format Target number?
– magicmass
Nov 12 at 20:03
"Target number": the phone# you're searching for in your Call log. "Format" The PhoneNumberUtils method you need to ensure the format of your target # matches the format in your Call log.
– paulsm4
Nov 12 at 20:59
|
show 2 more comments
I have function that collects all call logs, Incoming, outgoing and missed. It also gives me the call duration, date, type and time.
I want to search through this Call log for a specific number, "12345678".
Function:
StringBuffer sb = new StringBuffer();
Cursor managedCursor = getContentResolver().query(CallLog.Calls.CONTENT_URI, null, null, null, null);
int snumber = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE);
int date = managedCursor.getColumnIndex(CallLog.Calls.DATE);
int duration = managedCursor.getColumnIndex(CallLog.Calls.DURATION);
sb.append("Call Log :");
String phNumber = null;
while (managedCursor.moveToNext()) {
phNumber = managedCursor.getString(snumber);
String callType = managedCursor.getString(type);
String callDate = managedCursor.getString(date);
Date callDayTime = new Date(Long.valueOf(callDate));
String callDuration = managedCursor.getString(duration);
String dir = null;
int dircode = Integer.parseInt(callType);
switch (dircode) {
case CallLog.Calls.OUTGOING_TYPE:
dir = "OUTGOING";
break;
case CallLog.Calls.INCOMING_TYPE:
dir = "INCOMING";
break;
case CallLog.Calls.MISSED_TYPE:
dir = "MISSED";
break;
}
sb.append("nPhone Number:--- " + phNumber +
" nCall Type:--- " + dir +
" nCall Date:--- " + callDayTime +
" nCall duration in sec :--- " +
callDuration);
sb.append("n----------------------------------");
}
System.out.println(phNumber);
Just wondering how I would do this?
Appreciate any suggestions or answers!
java android
I have function that collects all call logs, Incoming, outgoing and missed. It also gives me the call duration, date, type and time.
I want to search through this Call log for a specific number, "12345678".
Function:
StringBuffer sb = new StringBuffer();
Cursor managedCursor = getContentResolver().query(CallLog.Calls.CONTENT_URI, null, null, null, null);
int snumber = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE);
int date = managedCursor.getColumnIndex(CallLog.Calls.DATE);
int duration = managedCursor.getColumnIndex(CallLog.Calls.DURATION);
sb.append("Call Log :");
String phNumber = null;
while (managedCursor.moveToNext()) {
phNumber = managedCursor.getString(snumber);
String callType = managedCursor.getString(type);
String callDate = managedCursor.getString(date);
Date callDayTime = new Date(Long.valueOf(callDate));
String callDuration = managedCursor.getString(duration);
String dir = null;
int dircode = Integer.parseInt(callType);
switch (dircode) {
case CallLog.Calls.OUTGOING_TYPE:
dir = "OUTGOING";
break;
case CallLog.Calls.INCOMING_TYPE:
dir = "INCOMING";
break;
case CallLog.Calls.MISSED_TYPE:
dir = "MISSED";
break;
}
sb.append("nPhone Number:--- " + phNumber +
" nCall Type:--- " + dir +
" nCall Date:--- " + callDayTime +
" nCall duration in sec :--- " +
callDuration);
sb.append("n----------------------------------");
}
System.out.println(phNumber);
Just wondering how I would do this?
Appreciate any suggestions or answers!
java android
java android
edited Nov 12 at 19:52
asked Nov 12 at 18:46
magicmass
258
258
1
Post your function
– Arahasya
Nov 12 at 19:17
@Arahasya, posted function
– magicmass
Nov 12 at 19:45
1
It sounds like you're on the right track: 1) Format "target number" PhoneNumberUtils to match the locale in your database, then, 2) in your loop, check if "targetNumber" equals "phNumber".
– paulsm4
Nov 12 at 19:59
Hi, thanks for the help! What do you mean by format Target number?
– magicmass
Nov 12 at 20:03
"Target number": the phone# you're searching for in your Call log. "Format" The PhoneNumberUtils method you need to ensure the format of your target # matches the format in your Call log.
– paulsm4
Nov 12 at 20:59
|
show 2 more comments
1
Post your function
– Arahasya
Nov 12 at 19:17
@Arahasya, posted function
– magicmass
Nov 12 at 19:45
1
It sounds like you're on the right track: 1) Format "target number" PhoneNumberUtils to match the locale in your database, then, 2) in your loop, check if "targetNumber" equals "phNumber".
– paulsm4
Nov 12 at 19:59
Hi, thanks for the help! What do you mean by format Target number?
– magicmass
Nov 12 at 20:03
"Target number": the phone# you're searching for in your Call log. "Format" The PhoneNumberUtils method you need to ensure the format of your target # matches the format in your Call log.
– paulsm4
Nov 12 at 20:59
1
1
Post your function
– Arahasya
Nov 12 at 19:17
Post your function
– Arahasya
Nov 12 at 19:17
@Arahasya, posted function
– magicmass
Nov 12 at 19:45
@Arahasya, posted function
– magicmass
Nov 12 at 19:45
1
1
It sounds like you're on the right track: 1) Format "target number" PhoneNumberUtils to match the locale in your database, then, 2) in your loop, check if "targetNumber" equals "phNumber".
– paulsm4
Nov 12 at 19:59
It sounds like you're on the right track: 1) Format "target number" PhoneNumberUtils to match the locale in your database, then, 2) in your loop, check if "targetNumber" equals "phNumber".
– paulsm4
Nov 12 at 19:59
Hi, thanks for the help! What do you mean by format Target number?
– magicmass
Nov 12 at 20:03
Hi, thanks for the help! What do you mean by format Target number?
– magicmass
Nov 12 at 20:03
"Target number": the phone# you're searching for in your Call log. "Format" The PhoneNumberUtils method you need to ensure the format of your target # matches the format in your Call log.
– paulsm4
Nov 12 at 20:59
"Target number": the phone# you're searching for in your Call log. "Format" The PhoneNumberUtils method you need to ensure the format of your target # matches the format in your Call log.
– paulsm4
Nov 12 at 20:59
|
show 2 more comments
1 Answer
1
active
oldest
votes
After lot of work, I finally found the solution. This code worked for me.
@Override
public void onCreate() {
String number = “12345678”
StringBuffer sb = new StringBuffer();
Cursor managedCursor = getContentResolver().query(CallLog.Calls.CONTENT_URI, null, null, null, null);
int snumber = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE);
int date = managedCursor.getColumnIndex(CallLog.Calls.DATE);
int duration = managedCursor.getColumnIndex(CallLog.Calls.DURATION);
List<String> callList = new ArrayList<String>();
while (managedCursor.moveToNext()) {
callList.add(number);
String callDate = managedCursor.getString(date);
callList.add(callDate);
String callDuration = managedCursor.getString(duration);
Date callDayTime = new Date(Long.valueOf(callDate));
break;
}
String phNumber = number;
callList.add(phNumber);
String callType = managedCursor.getString(type);
callList.add(callType);
if (callList.contains(phNumber)) {
System.out.println("The phone number is " + phNumber );
} else {
System.out.println(“Couldn’t find number ” + phNumber);
}
}
}
Hope this helps others!
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53268297%2fandroid-how-to-search-through-call-logs-for-a-specific-number%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
After lot of work, I finally found the solution. This code worked for me.
@Override
public void onCreate() {
String number = “12345678”
StringBuffer sb = new StringBuffer();
Cursor managedCursor = getContentResolver().query(CallLog.Calls.CONTENT_URI, null, null, null, null);
int snumber = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE);
int date = managedCursor.getColumnIndex(CallLog.Calls.DATE);
int duration = managedCursor.getColumnIndex(CallLog.Calls.DURATION);
List<String> callList = new ArrayList<String>();
while (managedCursor.moveToNext()) {
callList.add(number);
String callDate = managedCursor.getString(date);
callList.add(callDate);
String callDuration = managedCursor.getString(duration);
Date callDayTime = new Date(Long.valueOf(callDate));
break;
}
String phNumber = number;
callList.add(phNumber);
String callType = managedCursor.getString(type);
callList.add(callType);
if (callList.contains(phNumber)) {
System.out.println("The phone number is " + phNumber );
} else {
System.out.println(“Couldn’t find number ” + phNumber);
}
}
}
Hope this helps others!
add a comment |
After lot of work, I finally found the solution. This code worked for me.
@Override
public void onCreate() {
String number = “12345678”
StringBuffer sb = new StringBuffer();
Cursor managedCursor = getContentResolver().query(CallLog.Calls.CONTENT_URI, null, null, null, null);
int snumber = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE);
int date = managedCursor.getColumnIndex(CallLog.Calls.DATE);
int duration = managedCursor.getColumnIndex(CallLog.Calls.DURATION);
List<String> callList = new ArrayList<String>();
while (managedCursor.moveToNext()) {
callList.add(number);
String callDate = managedCursor.getString(date);
callList.add(callDate);
String callDuration = managedCursor.getString(duration);
Date callDayTime = new Date(Long.valueOf(callDate));
break;
}
String phNumber = number;
callList.add(phNumber);
String callType = managedCursor.getString(type);
callList.add(callType);
if (callList.contains(phNumber)) {
System.out.println("The phone number is " + phNumber );
} else {
System.out.println(“Couldn’t find number ” + phNumber);
}
}
}
Hope this helps others!
add a comment |
After lot of work, I finally found the solution. This code worked for me.
@Override
public void onCreate() {
String number = “12345678”
StringBuffer sb = new StringBuffer();
Cursor managedCursor = getContentResolver().query(CallLog.Calls.CONTENT_URI, null, null, null, null);
int snumber = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE);
int date = managedCursor.getColumnIndex(CallLog.Calls.DATE);
int duration = managedCursor.getColumnIndex(CallLog.Calls.DURATION);
List<String> callList = new ArrayList<String>();
while (managedCursor.moveToNext()) {
callList.add(number);
String callDate = managedCursor.getString(date);
callList.add(callDate);
String callDuration = managedCursor.getString(duration);
Date callDayTime = new Date(Long.valueOf(callDate));
break;
}
String phNumber = number;
callList.add(phNumber);
String callType = managedCursor.getString(type);
callList.add(callType);
if (callList.contains(phNumber)) {
System.out.println("The phone number is " + phNumber );
} else {
System.out.println(“Couldn’t find number ” + phNumber);
}
}
}
Hope this helps others!
After lot of work, I finally found the solution. This code worked for me.
@Override
public void onCreate() {
String number = “12345678”
StringBuffer sb = new StringBuffer();
Cursor managedCursor = getContentResolver().query(CallLog.Calls.CONTENT_URI, null, null, null, null);
int snumber = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE);
int date = managedCursor.getColumnIndex(CallLog.Calls.DATE);
int duration = managedCursor.getColumnIndex(CallLog.Calls.DURATION);
List<String> callList = new ArrayList<String>();
while (managedCursor.moveToNext()) {
callList.add(number);
String callDate = managedCursor.getString(date);
callList.add(callDate);
String callDuration = managedCursor.getString(duration);
Date callDayTime = new Date(Long.valueOf(callDate));
break;
}
String phNumber = number;
callList.add(phNumber);
String callType = managedCursor.getString(type);
callList.add(callType);
if (callList.contains(phNumber)) {
System.out.println("The phone number is " + phNumber );
} else {
System.out.println(“Couldn’t find number ” + phNumber);
}
}
}
Hope this helps others!
answered Nov 14 at 12:24
magicmass
258
258
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53268297%2fandroid-how-to-search-through-call-logs-for-a-specific-number%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Post your function
– Arahasya
Nov 12 at 19:17
@Arahasya, posted function
– magicmass
Nov 12 at 19:45
1
It sounds like you're on the right track: 1) Format "target number" PhoneNumberUtils to match the locale in your database, then, 2) in your loop, check if "targetNumber" equals "phNumber".
– paulsm4
Nov 12 at 19:59
Hi, thanks for the help! What do you mean by format Target number?
– magicmass
Nov 12 at 20:03
"Target number": the phone# you're searching for in your Call log. "Format" The PhoneNumberUtils method you need to ensure the format of your target # matches the format in your Call log.
– paulsm4
Nov 12 at 20:59