Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Mobile Development > BOOK: Beginning Android Application Development
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old January 2nd, 2013, 03:00 PM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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();
    }   
}
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 02:28 AM



All times are GMT -4. The time now is 06:23 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.