我有一个API,我希望用户登录到AWS Cognito,但我不想强迫应用程序开发人员使用android aws sdk。我怎样才能做到这一点?我猜Cognito有一个api,但我不确定那会是什么?我看过aws android文档,但他们专注于sdk的使用。
答案 0 :(得分:0)
如果您想在没有任何其他api的情况下登录。那么您必须尝试像sqlite这样的本地数据库。
public class DataBaseHelper extends SQLiteOpenHelper {
private String TAG = "DataBaseHelper";
private SQLiteDatabase mSqLiteDatabase;
private Context mContext;
/*Constructor call when you initialize DataBasseHelper class*/
public DataBaseHelper(Context context) {
super(context, DataBaseConstants.DATABASE_NAME, null, DataBaseConstants.DATABASE_VERSION);
this.mContext = context;
}
/*onCreate Method is used to create table */
@Override
public void onCreate(SQLiteDatabase db) {
Logger.e(TAG, "call onCreate");
db.execSQL("create table userInfo (id integer primary key AUTOINCREMENT, email text NOT NULL,password text NOT NULL, createdDate text NOT NULL)");
}
/*onUpgrade Method call when database version changed,
that time exsting table delete and new table create.
when we want new table create that time onCreate method will use.*/
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Logger.e(TAG, "call onUpgrade");
if (oldVersion < newVersion) {
db.execSQL("DROP TABLE " + "tableName");
onCreate(db);
}
}
/*onCopydatabase Method is used to copy existing database*/
public boolean onCopyDatabase(Context context) {
Logger.e(TAG, "call onCopyDatabase");
try {
InputStream inputStream = context.getAssets().open(DataBaseConstants.DATABASE_NAME);
String dbPath = mContext.getDatabasePath(DataBaseConstants.DATABASE_NAME).getPath();
String outFileName = dbPath + "/" + DataBaseConstants.DATABASE_NAME;
Logger.e(TAG, "Database path is : " + outFileName);
OutputStream outputStream = new FileOutputStream(outFileName);
byte[] buff = new byte[1024];
int length = 0;
while ((length = inputStream.read(buff)) > 0) {
outputStream.write(buff, 0, length);
}
outputStream.flush();
outputStream.close();
Log.w(TAG, "DataBase copied");
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
}