Access to call log

RimesRimes USMember
edited August 2014 in Xamarin.Android

Hi,

i am trying to access the call log, Here i my code:

    Android.Net.Uri uri = CallLog.ContentUri;
        String[] projection = {
                                   CallLog.Calls.CachedName,
                                   CallLog.Calls.Duration
                               };
        string queryFilter = String.Format("{0}={1}", CallLog.Calls.Type, (int)CallType.Missed);
        var cr = new CursorLoader(activity, uri, projection, queryFilter, null, null);
        var cursor = (ICursor)cr.LoadInBackground(); //**here is where i get the error**

        int id_temp = 0;
        if (cursor.MoveToFirst())
        {
            do
            {
                callInfoList.Add(new CallInfoDetails
                {
                    name = cursor.GetString(cursor.GetColumnIndex(projection[0])),
                    duration = cursor.GetInt(cursor.GetColumnIndex(projection[1])),
                    id = id_temp++ 
                });

            } while (cursor.MoveToNext());
        }

I don't know for sure, but i think that this might be something with the permissions. Before i was trying to read the contacts and i got an error at the same point. After setting "android.permission.READ_CONTACTS" i could read the contacts. Now i have set the permission "uses-permission android:name="android.permission.READ_CALL_LOG" but still getting the error.

Does anybody has an idea what else i could try ?

Kind Regards
Semir

Posts

  • RimesRimes USMember
    edited August 2014

    I found the error, it is this line:

                 String[] projection = { 
    

    when i use
    string[] projection = {

    instead it works fine. I must admit that i dont get it why this is an error (since String and string should be the same)

    Since i am dealing with content providers one question about them. How do i access a content resolver when i do not have an activity ?
    For example i am running a service and when i get an event i want to read something from a content provider. Do i have to copy the activity which started my service in a variable so that i can always access it (and use it to create the content resolver) ?

    Kind regards
    semir

Sign In or Register to comment.