Accessing to the device call Log history

Hi fuse,

I am developing the selfcare application using fuse tools. That is an amazing experience and up to now I have been following your documentation. Now I want to access to the device call Log history and get it. I followed your foreign code documentation and tried it with UNO file. But sadly I can’t understand the correct way to do this. Is there any documentation or API to do this? Please help me.

Having googled just a little, I found that you can read call log on Android, and a pretty clear understanding that you can not access call log on iOS.

What you need to do next, is wrap the native Java code in a Foreign code module. As an example, take a look at fuse-contacts library which accesses a somewhat related functionality.

Hope this helps!

Hi Fuse,
I tried to clone and run the ‘fuse-contacts library’. But unable to preview it and this is the error I am getting,
‘contacts_example.unoproj(7.13): E0100: Package ‘Android’ was not found’
‘E:\fuse-contacts-master\contacts_example.unoproj(7,14): Error E0100: Package ‘Android’ was not found’
Please provide me a solution. Thank you!

We do not provide support for 3rd party libraries. Please log a ticket on the repository for its author to know there is an issue.

As a side note, I only provided the link for reference on how wrapping something in Foreign code looks like. You should use the code there as a guide to writing your own module that deals with the call log, which you initially asked about.

Hi Fuse,
Still I am trying to achieve my target with foreign code. I tried several examples and then came up again with this. I haven’t completed this task yet. When I am trying to compile my code it gave error like that. It is showing as ‘cannot find symbol’ for ‘getColumnIndex’. Can anyone please help me to figure this out.

.... Building Android app
2/2: CallHistory.apk
E:\Project\...ForeignCode\CallHistory\build\Android\Debug\app\src\main\java\com\foreign\CallLog.java:43: error: cannot find symbol                                                                                                                                    
String num= c.getString(c.getColumnIndex(CallLog.Calls.NUMBER));// for  number
                                           ^
  symbol:   variable Calls
  location: class CallLog  
....  

my uno file - CallLog.uno

using Uno.Threading;
using Uno;
using Uno.UX;
using Uno.Compiler.ExportTargetInterop;
using Android;
using Uno.Permissions;


using Fuse;
using Fuse.Scripting;

[extern(Android) ForeignInclude(Language.Java, "android.app.Activity",
                                               "android.provider.CallLog.Calls",
                                               "android.database.Cursor", 
                                               "android.content.Context",
                                               "android.os.Bundle",
                                               "android.net.Uri")]

[UXGlobalModule]
public class CallLog : NativeModule{
    static readonly CallLog _instance;
    public CallLog(){
        if (_instance != null) return;
    	_instance = this;
    	Resource.SetGlobalKey(_instance, "CallLog");
        AddMember(new NativeFunction("callHistory",(NativeCallback)callHistory));
    }

    object callHistory(Context c, object[] args){
        callHistoryImpl();
        return null;
    }

    // public void TakeCallLog(object a1, EventArgs a2)
    // {
    //     var permissionPromise = Permissions.Request(Permissions.Android.READ_CALL_LOG);
    //     permissionPromise.Then(OnPermitted, OnRejected);
    // }

    // void OnPermitted(PlatformPermission permission)
    // {
    //     debug_log "Woo, we can take the picture now";
    // }

    // void OnRejected(Exception e)
    // {
    //     debug_log "Blast: " + e.Message;
    // }

    [Foreign(Language.Java)]
    public static extern(Android) string callHistoryImpl()
    @{
            // context.runOnUiThread(new Runnable(){
            //     public void run(){
                    //Toast.makeText(com.fuse.Activity.getRootActivity(),"Hi Fuse!",Toast.LENGTH_LONG).show();
                    //Cursor c = managedQuery(allCalls, null, null, null, null);
                    Uri allCalls = Uri.parse("content://call_log/calls");
                    Cursor c = com.fuse.Activity.getRootActivity().getContentResolver().query(allCalls, null, null, null, null);

                    String num= c.getString(c.getColumnIndex(CallLog.Calls.NUMBER));// for  number
                    String name= c.getString(c.getColumnIndex(CallLog.Calls.CACHED_NAME));// for name
                    String duration = c.getString(c.getColumnIndex(CallLog.Calls.DURATION));// for duration
                    int type = Integer.parseInt(c.getString(c.getColumnIndex(CallLog.Calls.TYPE)));// for call type, Incoming or out going.
        //         }

        // }); 
        return null;

    @}      

    static extern(!Android) string callHistoryImpl(){
        debug_log("Notifications not supported on this platform.");
        return null;
    }

}

The problem is that your Uno class has the same CallLog name as the Android package "android.provider.CallLog", so the code is confused about where it should find the Calls property.

Change the name of the module and this issue will go away.

Hi Fuse,

Thank you very much for your continuous support! I successfully completed it and time to move to a next target. Fingerprint authentication in android! Thank you again mate!

Good stuff! Do you think you could share the code on github?

Hi mate,
I have code for getting a full History and last callLog. If you want to get data for a specific date you should have to modify it with limit. I am happy to share this code and you can modify it.
Thank You!

Awesome! Please make a repository on github, and share the link with us here and on Slack community. Someone might even come up with a pull request for improvements!

Hey mate,
I made a repository as a fuse-CallLogHistory on github.

It is now open for a future improvements!