如何保存和检索的SQLite Android的路径图像 [英] How To Save and Retrieve path image in SQLite android

查看:106
本文介绍了如何保存和检索的SQLite Android的路径图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要保存在我的应用程序检索图片路径

i want to save and retrieve image path in my application

这是我的DBhelper

this is my 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

and this is my 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路径在我的数据库?
请大家帮我:)

how can i save path from cameraActivity in my database?? please help me :)

我把code对startCamera方法,,这code这样的

i put code to inserting on startCamera method,,this code like this

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);

}

和则此code来检索图片

and then this code to retrieve this image

if(helper.getGamb(c).equals("")){
        System.out.println("gamb kosong");
        detGam.setImageResource(R.drawable.gambarnf);

    }else detGam.setImageDrawable(Drawable.createFromPath(helper.getGamb(c)));

您必须解决我的code ??非常感谢你:)

you have solution to my code??thank you very much :)

推荐答案

您可以使用的onActivityResult 捕捉的照片后,保存路径。

You can use onActivityResult for saving path after capturing photo.

@Override
protected 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();
    }
}

这篇关于如何保存和检索的SQLite Android的路径图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆