A
A
ArturPendragonOfficial2021-02-28 17:14:21
Android
ArturPendragonOfficial, 2021-02-28 17:14:21

What is the right way to implement Content Provider in my little code?

I get a list of contacts from my phone and I want to transfer the received list through the Intent to the activity. To then use it in recyclerView. But I don’t catch up on how to do it. Because I don't understand what type of change.
result in the end.

class AsyncService() : IntentService("MyAsyncService") {

    override fun onHandleIntent(intent: Intent?) {
        var cols = arrayListOf<String>(
                ContactsContract.CommonDataKinds.Phone._ID,
                ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
                ContactsContract.CommonDataKinds.Phone.NUMBER).toTypedArray()
        
            var result = contentResolver.query(
                    ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                    cols,
                    null,
                    null,
                    ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME
            )
            val intent = Intent("your_action")
            intent.putExtra("key", result.toString())
            LocalBroadcastManager.getInstance(this).sendBroadcast(intent)

    }
    
}


I want to get in MainActivity
val response = intent.getStringExtra("key")

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2021-02-28
@ArturPendragonOfficial

Why is there a service? Do the same in activation. Just take it to another thread.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question