Accessing custom content provider from different app

后端 未结 5 1773
醉梦人生
醉梦人生 2020-12-17 10:15

Hello i have created an android app that uses a custom content provider named CustomCP, it implements all methods and everything works fine while managing data inside the ap

5条回答
  •  悲&欢浪女
    2020-12-17 11:13

    You can use below code to get the content provider data in other app.. You need to use content resolver to fetch the data..

    try {
        //URL provided in first app while creating the content provider
        val URL = "content://com.test.localstorage.MyContentProvider/authentication"
        val data = Uri.parse(URL)
        val cursor: Cursor? = contentResolver.query(data, null, null, null, "user_id")
    
        if (cursor != null) {
            if (cursor.moveToFirst()) {
                do {
                    return cursor.getString(cursor.getColumnIndex("user_id")).toString()
                } while (cursor.moveToNext())
            }
        }
    } catch (ex: Exception) {
        ex.printStackTrace()
    }
    

提交回复
热议问题