Member-only story
This is the real case from my project where App A generate unique code and App B need to use the same code as well. There are 2 solutions that I can think of for this problem :
- Both app will generate same unique code programatically. However from Settings.Secure.ANDROID_ID, Firebase ID, to UUID, none from these options can fit into the case.
- App A generate unique code and pass the data to App B through ContentProvider
The first step is to create the ContentProvider class inside App A. The class will be responsible to create database, keep and relay the data when there is query.
/**
* To send device code data to PTT Apps
*/
class AccountProvider : ContentProvider() {
companion object {
val PROVIDER_NAME = "live.onedata.vo.tablet.AccountProvider"
val URL = "content://$PROVIDER_NAME/data"
val CONTENT_URI = Uri.parse(URL)
val DEVICECODE = "devicecode"
}
var deviceCode = ""
private var db: SQLiteDatabase? = null
val DATABASE_NAME = "vo_tablet"
val TABLE_NAME = "device_code"
val DATABASE_VERSION = 1
val CREATE_DB_TABLE = " CREATE TABLE " + TABLE_NAME +
" (_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
" devicecode TEXT NOT NULL);"
/**
* Helper class that actually creates and manages
* the provider's underlying data repository.
*/
inner class DatabaseHelper constructor(context: Context?) :
SQLiteOpenHelper(context, DATABASE_NAME, null, DATABASE_VERSION) {
override…