Android Question Work Profile

Serge Nova

Member
Hello Dear Programmers,
I have a problem with a work profile application. I have the codes running on Android Studio but I can't convert it to B4X so I need help.

Here is the code for Android Studio:

For contacts (Link)

Get work and personal contacts:
override fun onCreateLoader(id: Int, args: Bundle?): Loader<Cursor> {
        val nameFilter = Uri.encode("a") // names that start with a
        val contentURI = when (id) {
            PERSONAL_CONTACTS_LOADER_ID -> ContactsContract.Contacts.CONTENT_URI
            else -> {
                ContactsContract.Contacts.ENTERPRISE_CONTENT_FILTER_URI
                    .buildUpon()
                    .appendPath(nameFilter)
                    .appendQueryParameter(
                        ContactsContract.DIRECTORY_PARAM_KEY,
                        ContactsContract.Directory.ENTERPRISE_DEFAULT.toString()
                    )
                    .build()
            }
        }
        return CursorLoader(
            this, contentURI, arrayOf(
                ContactsContract.Contacts.DISPLAY_NAME_PRIMARY
            ), null, null, null
        )
    }

And for Apps (link)

Get work and personnal apps:
override fun onCreate(savedInstanceState: Bundle?) {

     ...

     val crossProfileApps = getSystemService(CrossProfileApps::class.java)
       val userHandles = crossProfileApps.targetUserProfiles
       val label = crossProfileApps.getProfileSwitchingLabel(userHandles.first())
        binding.button.apply {
            text = label
            setOnClickListener {
                crossProfileApps.startMainActivity(
                    componentName,
                    userHandles.first()
                )
            }
        }
    }

I try to use code similar to this but nothing works:
B4X code:
    Dim cr As ContentResolver
    Dim u As Uri
    u.Parse("content://com.android.contacts/entreprise_default")
    cr.Initialize("cr")
    Dim crsr As Cursor = cr.Query(u, Null, "", Null, "")
    Log("Size: " & crsr.RowCount)
    printCursor(crsr)
    
Private Sub printCursor (c As Cursor)
    For r = 0 To c.RowCount - 1
        c.Position = r
        For col = 0 To c.ColumnCount - 1
            Log("Info: " & c.GetColumnName((col) & ": " & c.GetString2(col)))
        Next
    Next
End Sub

If Anyone can help me to convert this code or give me other ideas then it is welcome.

Thanks
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…