B4A Library AndroidProviders (Calendars, Contacts, Calls Log, Telephony, SMS, MMS and more

This is a wrapper for this Github project.

Android-content-providers.png


AndroidProviders
Author: Manfred Ssykor <DonManfred>
Version: 1.1
  • BrowserProvider
    Methods:
    • Initialize
    • IsInitialized As Boolean
    Permissions:
    • com.android.browser.permission.READ_HISTORY_BOOKMARKS
    Properties:
    • Bookmarks As Cursor [read only]
    • Searches As Cursor [read only]
  • CalendarProvider
    Methods:
    • Initialize
    • IsInitialized As Boolean
    • getCalendarByID (calendarId As Long) As Calendar
    • getEvents (calendarId As Long) As Cursor
    • updateCalendar As Int
    Permissions:
    • android.permission.READ_CALENDAR
    • android.permission.WRITE_CALENDAR
    Properties:
    • Calendars As Cursor [read only]
  • CallsProvider
    Methods:
    • Initialize
    • IsInitialized As Boolean
    Permissions:
    • android.permission.READ_CALL_LOG
    Properties:
    • Calls As Cursor [read only]
  • ContactsProvider
    Methods:
    • Initialize
    • IsInitialized As Boolean
    Permissions:
    • android.permission.READ_CONTACTS
    Properties:
    • Contacts As Cursor [read only]
  • DictionaryProvider
    Methods:
    • Initialize
    • IsInitialized As Boolean
    Permissions:
    • android.permission.READ_USER_DICTIONARY
    Properties:
    • Words As Cursor [read only]
  • MediaProvider
    Methods:
    • Initialize
    • IsInitialized As Boolean
    Permissions:
    • android.permission.READ_EXTERNAL_STORAGE
    Properties:
    • AlbumsExternal As Cursor [read only]
    • AlbumsInternal As Cursor [read only]
    • ArtistsExternal As Cursor [read only]
    • ArtistsInternal As Cursor [read only]
    • AudiosExternal As Cursor [read only]
    • AudiosInternal As Cursor [read only]
    • FilesExternal As Cursor [read only]
    • FilesInternal As Cursor [read only]
    • GenresExternal As Cursor [read only]
    • GenresInternal As Cursor [read only]
    • ImagesExternal As Cursor [read only]
    • ImagesInternal As Cursor [read only]
    • PlaylistsExternal As Cursor [read only]
    • PlaylistsInternal As Cursor [read only]
    • VideosExternal As Cursor [read only]
    • VideosInternal As Cursor [read only]
  • TelephonyProvider
    Methods:
    • Initialize
    • IsInitialized As Boolean
    • getMMS (filter As String) As Cursor
    • getSMS (filter As String) As Cursor
    Permissions:
    • android.permission.READ_SMS
    Properties:
    • Carriers As Cursor [read only]
    • Conversations As Cursor [read only]
    • Threads As Cursor [read only]


Notes:
- ALL Content-Providers doe only READ as yet. For the Calendars-Povider i´ll make an update where you can Update Events and Calendars. It is not done as yet. All other Providers except Calendars does not have any update-methods. So you just can READ all the data

- ALL Providers will return a CURSOR to iterate through the results!

As Example i´ll post code to get all Contacts. ALL other Providers can be used similar.

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim contp As ContactsProvider
End Sub
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    contp.Initialize("")
    '
    Dim c As Cursor
    c = contp.Contacts
    If c.RowCount > 0 Then
        For i = 0 To c.RowCount-1
            c.Position = i
            LogColor("===========================", Colors.Green)
            Dim colcount As Int = c.ColumnCount
            Log("columns="&colcount)
            For o = 0 To colcount -1
                Log(c.GetColumnName(o)&"="&c.GetString(c.GetColumnName(o)))           
            Next           
        Next
    End If
    Log("Contacts = "&c.RowCount)

If you want to donate for my work building the wrapper you can do it here:
 

Attachments

  • AndroidContentProvidersEx.zip
    7.1 KB · Views: 970
  • libAndroidProvidersV1.0.0.zip
    50.7 KB · Views: 807
  • libAndroidProvidersV1.1.0.zip
    50.5 KB · Views: 782
Last edited:

wineos

Member
Licensed User
Longtime User
Hi

I have tried the getEvent function, and found that the no. of columns of the returned cursor was not stable. Different event records will have different columns exist.

Any idea?

Thanks!
 

wineos

Member
Licensed User
Longtime User
Hi,

I want to access the calendar Instances records, read, update and delete. How can I use your library to do these functions?

When will the Calendar Provider be ready for update?

Thanks!
 

wineos

Member
Licensed User
Longtime User
Sorry DonManfred,

At last, I found that CalendarContract.Instances is only readable. It cannot edit. :p

Thanks!
 

swamisantosh

Member
Licensed User
Longtime User
CallsProvider
Methods:

  • Initialize (EventName As String)
  • IsInitialized As Boolean
  • getMMS (filter As String) As Cursor
  • getSMS (filter As String) As Cursor
i'm new in coding
please provide code to read SMS and CallsProvider
 

DonManfred

Expert
Licensed User
Longtime User
i'm new in coding
Then learn the language.

please provide code to read SMS and CallsProvider

There are an example for a provider in post #1
The other providers are similar and are easily to create by yourself

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim cp As CallsProvider
End Sub

B4X:
    cp.Initialize("Calls")
    Dim aint As Cursor
    aint = cp.getSMS("ALL")
    Log("SMS = "&aint.RowCount)
    If aint.RowCount > 0 Then
        For i = 0 To aint.RowCount-1
            aint.Position = i
          
            Dim colcount As Int = aint.ColumnCount
            Log("columns="&colcount)
            For o = 0 To colcount -1
                Log(aint.GetColumnName(o)&"="&aint.GetString(aint.GetColumnName(o)))              
            Next              
            LogColor("---------------------------", Colors.Magenta)
        Next
    End If
 
Last edited:

JohnC

Expert
Licensed User
Longtime User
Please provide more examples/Syntax for the "Filer" parameter of the .getSMS(filter) and .MMS(filter) calls.

I ask because no matter what I put for 'filter' using ("inbox") or ("send"), the routine will always return ALL SMS records.

Thanks!
 

DonManfred

Expert
Licensed User
Longtime User
the routine will always return ALL SMS records.
I guess it comes from the wrong filter you are using....

B4X:
    public Cursor getSMS(String filter){
    Filter f= Filter.ALL;
        switch (filter) {
    case "ALL":
      f = Filter.ALL;
      break;
    case "INBOX":
      f = Filter.INBOX;
      break;
    case "OUTBOX":
        f = Filter.OUTBOX;
        break;
    case "SENT":
        f = Filter.SENT;
        break;
    case "DRAFT":
        f = Filter.DRAFT;
        break;
        }
        Data<Sms> calls = this.getObject().getSms(f);
        Cursor c = calls.getCursor();
      
        return c;
    }

Default is ALL

Filters are "ALL", "INBOX", "OUTBOX", "SENT" and "DRAFT" (in THIS CASE)
 

JohnC

Expert
Licensed User
Longtime User
Thanks for the quick response.

Curious, the stock SMS/MMS messaging app on my Samsung S4 doesn't have any of folders in it - is this the norm or is just Samsung not implementing these folders?
 
Top