java-如何在SQLite android中保存和检索路径图像

java-如何在SQLite android中保存和检索路径图像,第1张

概述我想在我的应用程序中保存检索图像路径这是我的DBhelperpublicvoidinsert(Stringkdstore,Stringnama,Stringalamat,Stringkodepos,Stringnotel,Stringlng,Stringlat,StringPerus,Stringgambar){//waktu=newDate().toString();Content

我想在我的应用程序中保存和检索图像路径

这是我的DBhelper

public voID insert(String kdstore,String nama, String alamat, String kodepos, String notel,         String lng, String lat ,String Perus,String gambar){    //waktu = new Date().toString();    ContentValues cv = new ContentValues();    cv.put("kdstore", kdstore);    cv.put("nama", nama);    cv.put("alamat", alamat);    cv.put("kodepos", kodepos);    cv.put("notel", notel);    cv.put("lng", lng);    cv.put("lat", lat);    cv.put("Perus", Perus);    cv.put("gambar", df.filename);    System.out.println();    getWritableDatabase().insert("alfamapp", "name", cv);}

这是我的startCameraActivity

_path=Environment.getExternalStorageDirectory().getPath() + "/DCIM/Camera/";        filename =  String.format(System.currentTimeMillis()+".jpg");        file file = new file(_path, filename);        try {        file.createNewfile();        } catch (IOException e) {        e.printstacktrace();        }        Uri outputfileUri = Uri.fromfile(file);        Intent intent = new Intent(androID.provIDer.MediaStore.ACTION_IMAGE_CAPTURE);        intent.putExtra(MediaStore.EXTRA_OUTPUT, outputfileUri);        startActivityForResult(intent, IMAGE_CAPTURE); 

如何在我的数据库中保存来自cameraActivity的路径?
请帮我 :)

我把代码插入到startCamera方法上,这样的代码

public voID startCamera() {    Cursor c = helper.getByID(almagID);    c.movetoFirst();    file = new file(_path, filename);    try {    file.createNewfile();    } catch (IOException e) {    e.printstacktrace();    }        file1 = new file(_path, filename);    try {    file1.createNewfile();    } catch (IOException e) {    e.printstacktrace();    }    Uri outputfileUri = Uri.fromfile(file);    Intent intent = new Intent(androID.provIDer.MediaStore.ACTION_IMAGE_CAPTURE);    intent.putExtra(MediaStore.EXTRA_OUTPUT, outputfileUri);    finishActivity(IMAGE_CAPTURE);    Uri outputfileUri1 = Uri.fromfile(file1);    intent.putExtra(MediaStore.EXTRA_OUTPUT, outputfileUri1);    startActivityForResult(intent, IMAGE_CAPTURE);    System.out.println(file1);    Dbhelper helper = new Dbhelper(this);    sqliteDatabase db = helper.getWritableDatabase();    db.execsql("update alfamapp set gambar ='"+file+"',gambar1 ='"+file1+"' " +                "where kdstore='"+helper.getKdStore(c)+"'");    db.execsql("insert into image (kdstore,image1) values ('"+helper.getKdStore(c)+"','"+file+"')");    db.execsql("update image set image2 ='"+file1+"' where kdstore='"+helper.getKdStore(c)+"'");    db.close();    helper.close();    load();    System.out.println(db);}

然后使用此代码检索此图像

if(helper.getGamb(c).equals("")){        System.out.println("gamb kosong");        detGam.setimageResource(R.drawable.gambarnf);    }else detGam.setimageDrawable(Drawable.createFromPath(helper.getGamb(c)));

您对我的代码有解决方案?非常感谢:)

解决方法:

您可以在拍摄照片后使用onActivityResult保存路径.

@OverrIDeprotected voID onActivityResult(int requestCode, int resultCode, Intent data) {    // Todo auto-generated method stub    super.onActivityResult(requestCode, resultCode, data);    if( requestCode == IMAGE_CAPTURE && resultCode == Activity.RESulT_OK) {        DBHelper dbHelper = new DBHelper(this);        sqliteDatabase sql = dbHelper.getWritableDatabase();        sql.execsql("insert statement for inserting path to database");        sql.close();        dbHelper.close();    }}
总结

以上是内存溢出为你收集整理的java-如何在SQLite android中保存和检索路径图像全部内容,希望文章能够帮你解决java-如何在SQLite android中保存和检索路径图像所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1095406.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存