İş Tecrubesi
Eğitim Geçmişi
Sertifikalar & Başarılar
Kullanıcıya ait test sonucu bulunmamaktadır.
Dil Becerileri
Son Forum Aktiviteleri
3Local Veritabani icin Content Provider olusturma
Merhaba arkadaslar,
Offline Veritabani uzerinde calisiyorum. ListView uzerinden SimpleCursorAdapter kullanarak veritabanindan blgileri bir liste halinde gosteriyorum. Verileri Veritabanindan alirken Loader (bekleme mesaji) gostermek istiyorum. Loader kullanirken, CONTENT_URI isteniyo. Local Veritabanina ulasmak icin nasil bir CONTENT PROVIDER olusturmam lagzim.
Simdiden tskler :)
sql ekleme
.sqlite veritabanini assets klasorune yukle. Bu kodu onCreate() methodunda cagir. Uygulama acilfiginda, veritabanin telefonun local veritabanina kopyalansin.
[code]public void importDatabase() throws IOException{
boolean databaseExist = checkDatabase();
if(databaseExist){
Log.i(TAG, DB_NAME + " exists on the device");
}
else{
this.getWritableDatabase();
copyDatabase();
}
}
public boolean checkDatabase(){
File databaseFile = new File(DB_PATH + DB_NAME);
return databaseFile.exists();
}
private void copyDatabase() throws IOException{
Log.i(TAG, DB_NAME + " is being copied");
//Open your local db as the input stream
InputStream myInput = context.getAssets().open(DB_NAME);
//Path to the just created empty db
String outFileName = DB_PATH + DB_NAME;
//Open the empty db as the output stream
OutputStream myOutput = new FileOutputStream(outFileName);
//Transfer bytes from the input file to the output file
byte[] buffer = new byte[1024];
int length;
while((length = myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
}
//Close the streams
myOutput.flush();
myOutput.close();
myInput.close();
Log.i(TAG, DB_NAME + " has been copied to device");
}
//Open the database
public void open() throws SQLException{
String myPath = DB_PATH + DB_NAME;
db = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);
}
@Override
public synchronized void close() {
if(db != null)
db.close();
super.close();
}[/code]
DB_NAME = veritabani adi
DB_PATH = "/data/data/"+ keni package adi +"/databases/"; // telefonun veritabani yeri