Using the nativescript-contacts plugin with nativescript 5.0, Angular, and webpack.
Is there a way to retrieve the contact name based on the phone number?
The main issue is that I want to display a list of recent phone calls, but there is one problem.
Let me give you an example: 1. A call from an unknown number is received at 9:00 am. This displays the contact name as "unknown" with the caller's number in the list.
After ending this call at 9:10 am, the number is added to contacts.
At 10:00 am, a call from the same number is received.
Now, when I view the call log list in my Android App, I see two calls like this ->
10:00 am Jim Corbet 999988887777 9:00 am unknown 999988887777
Instead, I would like to display distinct phone log entries with the contact name if it is saved. === Or I will try querying the nativescript-contacts plugin to retrieve the contact name using the number (since this feature is not currently available).
I have attempted using Set() without success. I am struggling with implementing GROUP BY in my queries due to limited understanding.
Just to clarify, there are no errors in the program.
Here is the code related to the call logs:
var utilsModule = require("tns-core-modules/utils/utils");
public CallLog = android.provider.CallLog;
public Log = android.util.Log;
public Uri = android.net.Uri;
var callUri = this.Uri.parse("content://call_log/calls");
var strOrder = android.provider.CallLog.Calls.DATE + " DESC";
var context = utilsModule.ad.getApplicationContext();
var cr=context.getContentResolver();
var curCallLogs = cr.query(callUri, null, null, null, strOrder);
//I only need the latest 30 calls
for(var i=0;i<30;i++){
curCallLogs.moveToNext();
var strName=curCallLogs.getString(curCallLogs.getColumnIndex(android.provider.CallLog.Calls.CACHED_NAME));
callobject.callerNumber=curCallLogs.getString(curCallLogs.getColumnIndex(android.provider.CallLog.Calls.NUMBER));
}