0
我想要做的是打開一個圖像,這個圖像uri應該存儲在我的本地數據庫,然後我重新打開應用程序後插入的最後一張圖片將出現,但我有一個問題,當我重新打開應用程序的圖像不是從數據庫中的uri加載的。無法查看圖像通過存儲在Uql Sqlite
我的代碼:
private static final int PICK_IMAGE = 100;
private ImageView imageView;
SQLiteDatabase DB;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = (ImageView) findViewById(R.id.image_view);
DB = this.openOrCreateDatabase("test",MODE_PRIVATE,null);
DB.execSQL("CREATE TABLE IF NOT EXISTS users (uri VARCHAR)");
Cursor c = DB.rawQuery("SELECT * from users",null);
c.moveToLast();
int UriIndex = c.getColumnIndex("uri");
Uri image = Uri.parse(c.getString(UriIndex));
imageView.setImageURI(image);
Button pickImageButton = (Button) findViewById(R.id.pick_image_button);
pickImageButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
openGallery();
}
});
}
private void openGallery() {
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, PICK_IMAGE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK && requestCode == PICK_IMAGE) {
Uri imageUri = data.getData();
DB.execSQL("INSERT INTO users (uri) VALUES ('"+imageUri.toString()+"')");
imageView.setImageURI(imageUri);
}
}}
感謝。
非常感謝您,很棒的新信息^ _ ^ – SimpleProgramming