name of the folder which should be named as 'databases' not showing in data/data/<package name>, but the size of the file or database created(which i think is) is showing.
Code:
package com.example.itmupdates;
import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class DBAdapter {
public static final String KEY_ROWID="_ID";
public static final String KEY_TT_NAME="TT_NAME";
public static final String KEY_FILE_PATH="FILE_PATH";
public static final String TAG="DBAdapter";
public static final String DATABASE_NAME="WhatsITM_db";
public static final String DATABASE_TABLE="FILE_LOCATION";
public static final int DATABASE_VERSION=1;
private static final String DATABASE_CREATE="create table FILE_LOCATION " +
"(TT_NAME text"+
"_ID integer primary key autoincrement" +
"FILE_PATH text";
private final Context context;
private DatabaseHelper DBHelper;
private SQLiteDatabase db;
public DBAdapter(Context ctx)
{
this.context=ctx;
DBHelper=new DatabaseHelper(context);
}
private static class DatabaseHelper extends SQLiteOpenHelper
{
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
try
{
db.execSQL(DATABASE_CREATE);
}
catch(SQLException e)
{
e.printStackTrace();
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
Log.w(TAG, "Upgrading database from version"+oldVersion+"to"+newVersion);
db.execSQL("DROP TABLE IF EXISTS FILE_LOCATION");
onCreate(db);
}
}
public DBAdapter open()throws SQLException
{
db=DBHelper.getWritableDatabase();
return this;
}
public void close()
{
DBHelper.close();
}
}
Here in the starting activity
Code:
package com.example.itmupdates;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.app.Activity;
import android.content.Intent;
public class Start_point extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start_point);
try
{
String destpath="/data/data"+getPackageName()+"/databases/WhatsITM_db";
File f= new File(destpath);
if(!f.exists())
{
CopyDB(getBaseContext().getAssets().open("whatsitm_db"),new FileOutputStream(destpath));
}
}
catch(FileNotFoundException e)
{
e.printStackTrace();
}
catch(IOException e)
{
e.printStackTrace();
}
DBAdapter db=new DBAdapter(this);
db.open();
db.close();
Button btnstudent = (Button) findViewById(R.id.btnstudent);
btnstudent.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
startActivity(new Intent("com.example.itmupdates.Student"));
}
});
Button faculty = (Button) findViewById(R.id.btnfaculty);
faculty.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
startActivity(new Intent("com.example.itmupdates.Faculty"));
}
});
}
public void CopyDB(InputStream input,OutputStream out) throws IOException
{
byte[] buffer=new byte[1024];
int length;
while((length=input.read(buffer))>0)
{
out.write(buffer, 0, length);
}
input.close();
out.close();
}
}