Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Mobile Development > BOOK: Beginning Android Application Development
|
BOOK: Beginning Android Application Development
This is the forum to discuss the Wrox book Beginning Android Application Development by Wei-Meng Lee; ISBN: 978-1-1180-1711-1
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Android Application Development section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 2nd, 2013, 04:00 PM
Registered User
 
Join Date: Jan 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default name of the folder which should be named as 'databases' not showing in data/data/...

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Crystal not showing data tgraham Crystal Reports 4 September 9th, 2009 02:46 AM
Same data showing in PDF artarasan ASP.NET 2.0 Basics 1 July 3rd, 2007 01:10 AM
Incomplete Data Showing rameshjha ADO.NET 0 June 20th, 2006 06:46 AM
Unable to build folder named dfalconer VS.NET 2002/2003 2 October 28th, 2004 03:24 AM
Working with data from 2 databases piemur Classic ASP Databases 1 February 29th, 2004 03:28 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.