Reputation: 1
I create First App and his name "provides" and I use SQLite Database for create table and insert data to a table and everything is work. and I create Second App and his name "consumes" his app is responsible to receive data from my first app then I create Content Provider in the first app and this is code :
class Provider : ContentProvider() {
private lateinit var db: LoginSqliteHelper
override fun onCreate(): Boolean {
db = LoginSqliteHelper(context!!)
return true
}
override fun query(
uri: Uri,
projection: Array<out String>?,
selection: String?,
selectionArgs: Array<out String>?,
sortOrder: String?
): Cursor? {
return db.readableDatabase.query(
ConstantValue.Table_Name,
projection,
selection,
selectionArgs,
null,
null,
sortOrder
)
}
override fun getType(uri: Uri): String? {
return "vnd.android.cursor.dir/vnd.example.storge.provider"
}
override fun insert(uri: Uri, values: ContentValues?): Uri? {
TODO("Not yet implemented")
}
override fun delete(uri: Uri, selection: String?, selectionArgs: Array<out String>?): Int {
TODO("Not yet implemented")
}
override fun update(
uri: Uri,
values: ContentValues?,
selection: String?,
selectionArgs: Array<out String>?
): Int {
TODO("Not yet implemented")
}
}
then I Create Provider in the manifest
<provider
android:name=".sqlite.Provider"
android:authorities="com.example.storage"
android:enabled="true"
android:exported="true" />
for information the package name to first app is "com.example.storage" then I receive data from my first app in the second app by this method :
val uri = Uri.parse("content://com.example.storge")
val cursor = contentResolver.query(uri, null, null, null, null)
if (cursor != null){
while (cursor.moveToNext()) {
for (i in 0 until cursor.columnCount) {
Log.d(TAG, "$i - ${cursor.getColumnName(i)} ${cursor.getString(i)}")
}
}
cursor.close()
}
but the cursor is null , I do not know why null !?
The first application works effectively, but when I run the second application, it does not receive any data from the first application. What is the reason?
Upvotes: 0
Views: 55