public Drawable icon; \\ Some value in this field
I am creating a database in SQLite Manager. I want to store icon into the database. Another field is shown correctly, but when I take the icon field with datatype BLOB, it doesn’t display.
public void prettyPrint() {
public String appname = "asd";
public String pname = "asd";
public String versionName = "asd";
public int versionCode = 0;
public Drawable icon="android.im....";
Insall_app_db i1 = new Insall_app_db();
i1.createDatabse("appInfo3", getBaseContext());
i1.createTable("off_appinfo4", getBaseContext()); i1.insertDataUser("off_appinfo4", appid ,appname,pname, versionName, versionCode, icon, x);
}
package com.AppInfo;
import java.sql.Blob;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import android.R.drawable;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.drawable.Drawable;
public class Insall_app_db {
SQLiteDatabase sampleDB = null;
String PhoneNumber;
String UserId;
Cursor c;
ArrayList ar=new ArrayList();
public void createDatabse(String DbName,Context context)
{
sampleDB = context.openOrCreateDatabase(DbName,
context.MODE_WORLD_READABLE,null);
}
public void createTable(String Tablename,Context context)
{
sampleDB.execSQL("CREATE TABLE IF NOT EXISTS " +
Tablename +
"(app_id INT,app_name VARCHAR(255),pname VARCHAR(255),version_name VARCHAR(25),versionCode INT,icon BLOB,date DATE);");
}
public void DeleteTable(String Tablename,Context context)
{
sampleDB.execSQL("DROP TABLE off_appinfo4");
}
public void insertDataUser(String tableName,int app_id,String app_name,String pname,String version_name,int versionCode,String d,long date1)
{
sampleDB.execSQL("INSERT INTO " +
tableName +
" Values ("+app_id+",'"+app_name+"','"+pname+"','"+version_name+"','"+versionCode+"','"+d+"',"+date1+");");
}
public String GetUserData(Context context,String tablename)
{
c = sampleDB.rawQuery("SELECT User_Id FROM " +
tablename +
"", null);
if(c!=null)
{
if(c.moveToFirst())
{
do
{
UserId=c.getString(c.getColumnIndex("User_Id"));
}while(c.moveToNext());
}
}
return UserId;
}
public void close()
{
sampleDB.close();
}
}
You can convert your image into byte array and store that bytearray in blob filed in database. You can retrieve your image back from database as byte array.
How to get byte array from imageview:
Store byte array in database:
Retrieve image from byte array: