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: 983
  • libAndroidProvidersV1.0.0.zip
    50.7 KB · Views: 820
  • libAndroidProvidersV1.1.0.zip
    50.5 KB · Views: 798
Last edited:

jefflynn1974

Member
Licensed User
Longtime User
Hello!

How can I get the call logs? The class name is the same and when i use the CallsProvider I don't have .getcalls
 

DonManfred

Expert
Licensed User
Longtime User
I guess it must be different.
My guess was right. I used two time the same classname to wrap.

Library V1.1 updated in Post #1

Attached an Example to read the CallLog
 

Attachments

  • CallsEx.zip
    7.7 KB · Views: 357

swamisantosh

Member
Licensed User
Longtime User
with Library libAndroidProvidersV1.0.0 the sample code works fine,
but when i updated Library to libAndroidProvidersV1.1.0 i getting the error message
Line 30 : cp.Initialize("")

error message

B4A version: 5.80
Parsing code. (0.01s)
Compiling code. Error
Error compiling program.
Error description: Object reference not set to an instance of an object.
Occurred on line: 30
cp.Initialize("")
Word: (
please guide me
 

u2005k

Member
Licensed User
Longtime User
Hi Don,

When I try to use TelephonyProvider and Carriers I get following error.

Dim tp As TelephonyProvider
tp.Initialize

Dim c As Cursor
c = tp.Carriers
Error occurred on line: 95 (Main)
java.lang.SecurityException: No permission to write APN settings
at android.os.Parcel.readException(Parcel.java:1620)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
at android.content.ContentProviderProxy.query(ContentProviderNative.java:421)
at android.content.ContentResolver.query(ContentResolver.java:493)
at android.content.ContentResolver.query(ContentResolver.java:435)
at com.github.providers.core.AbstractProvider.getContentTableData(AbstractProvider.java:29)
at com.github.providers.android.telephony.TelephonyProvider.getCarriers(TelephonyProvider.java:108)
at de.donmanfred.TelephonyProviderWrapper.getCarriers(TelephonyProviderWrapper.java:112)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:708)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:337)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at b4a.example.main.afterFirstLayout(main.java:102)
at b4a.example.main.access$000(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5438)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)


Are there additional permissions required?

Thanks & regards...


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:
 

GaryK4

Member
Licensed User
Longtime User
I am trying to run this example. I installed the libraries.
When I run the program, it gives me an error on the Initialize
contp.Initialize("")

Error description: Object reference not set to an instance of an object.
Error occurred on line: 37
contp.Initialize("")
Word: (

Did I forget something
 
Top